Kubernetes CKA sample exam question 122 with answer

Question
Deploy a pod called secure-pod in secure namespace with image busybox which sleeps for 2600 seconds.
Configure the pod with environment variable called ENV_NAME and read the value from a ConfigMap. Set the environment value to prod.
Test that the environment variable is created and available for the container.
Create all dependent resources.

Answer
Create namespace:

kubectl create ns secure
Create ConfigMap:
kubectl create cm secure-cm --from-literal=env=prod -n secure
Generate pod manifest:
kubectl run secure-pod -n secure --image=busybox --dry-run=client -o yaml -- /bin/sh -c "sleep 2600"
Edit the manifest and add reference to ConfigMap:
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: secure-pod
  name: secure-pod
  namespace: secure
spec:
  containers:
  - args:
    - /bin/sh
    - -c
    - sleep 2600
    image: busybox
    name: secure-pod
    env:
    - name: ENV_NAME
      valueFrom:
        configMapKeyRef:
          name: secure-cm
          key: env
Deploy the pod and test using following command:
kubectl apply -f po.yaml
kubectl exec -it secure-pod -n secure -- env | grep "ENV_NAME"