# Before apply this manifest, create the ConfigMap as following.

# Method 1.
# kubectl create secret generic demo-k8s-secret --from-file=./appsettings.Kubernetes.json -n demo-k8s
# kubectl create secret generic demo-k8s-env-secret --from-env-file=./app.env -n demo-k8s

# Method 2.
# kubectl apply -f secret-env.yml -n demo-k8s
# kubectl apply -f secret-appsettings.yml -n demo-k8s
---
apiVersion: v1
kind: Pod
metadata:
  name: demo-k8s-pod # The name of the pod
  labels:
    app: demo-k8s
spec:
  containers:
    - name: demok8s
      image: karatejb/demo-k8s:latest # The Docker image
      ports:
        - containerPort: 5000
        - containerPort: 5001
      envFrom:
        - secretRef:
            name: demo-k8s-env-secret
      # env:
      #   - name: ASPNETCORE_ENVIRONMENT
      #     valueFrom:
      #       secretKeyRef:
      #         name: demo-k8s-env-secret
      #         key: ASPNETCORE_ENVIRONMENT
      #   - name: ASPNETCORE_FORWARDEDHEADERS_ENABLED
      #     valueFrom:
      #       secretKeyRef:
      #         name: demo-k8s-env-secret
      #         key: ASPNETCORE_FORWARDEDHEADERS_ENABLED
      volumeMounts:
        - name: secret-volume
          # mountPath: /app/config # DO NOT use this line, it will DELETE and RECREATE the /app
          mountPath: /app/appsettings.Kubernetes.json
          subPath: appsettings.Kubernetes.json
  volumes:
    - name: secret-volume
      secret:
        secretName: demo-k8s-secret

# Port forwarding for the Pods 
# kubectl port-forward [--address <ip>] <pod_name> 5001:5001
