apiVersion: apps/v1
kind: Deployment
metadata:
  name: myappspa
spec:
  selector:
    matchLabels:
      app: myapp   # This label identifies our application, used for filtering output
      component: spa    # This label identifies component, used for Service definition
      type: release    # This label identifies actual release vs. canary etc.      
  replicas: 2
  template:
    metadata:
      labels:
        app: myapp   # This label identifies our application, used for filtering output
        component: spa    # This label identifies component, used for Service definition
        type: release    # This label identifies actual release vs. canary etc.
    spec:
      securityContext:   # Best practice for security - if possible never run as root (which is default)
        runAsNonRoot: true     # Make sure container images do not use root
      initContainers:
      - name: info
        image: ubuntu
        securityContext:
          runAsUser: 1001
        command: ["/bin/bash"]
        args: ["-c", "echo $NAMESPACE > /opt/bitnami/nginx/html/info/namespace.txt"]
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        volumeMounts:
          - name: info
            mountPath: /opt/bitnami/nginx/html/info
      containers:
      - name: myappspa
        image: YOUROCIRNAME/myappspa:v2   # Best practice - always define specific tag, do not rely on latest
        imagePullPolicy: Always    # Best practice for security - user will no access to image might get it from local cache
        env:
        - name: NGINX_HTTP_PORT_NUMBER
          value: "8080"
        ports:  # We cannot run on ports <1024 because that would require root
        - containerPort: 8080
        livenessProbe:    # Best practice for stability - always define probes to detect hanged process
          httpGet:
            path: /health
            port: 8080
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
        resources:    # Best practice for stability
          limits:    # Always limit resources to keep nodes healthy (eg. prevent memory leak to hurt other containers)
            cpu: 100m
            memory: 128Mi
          requests:     # Always define request so scheduler can decide better about placements (required for node autoscaling)
            cpu: 100m
            memory: 128Mi
        volumeMounts:
          - name: info
            mountPath: /opt/bitnami/nginx/html/info
          - name: config-volume
            mountPath: /opt/bitnami/nginx/conf/vhosts/
      volumes:
        - name: config-volume
          configMap:
            name: healthvhostconf
        - name: info
          emptyDir: {}
      imagePullSecrets:
        - name: ocirsecret
