Kubernetes CKA sample exam question 102 with answer

Question
Create secure environment variables and configure the pod as per below specifications:

pod name: secure-pod
Image: nginx
Environment variables:
Key		Value
username	admin
password	cka@2022!
Answer
It is a good practice to inject credentials and other confidential information as a secret. When you create a secret, it automatically applies base64 encoding on the data.
If you want to make all data keys defined in the secret to be available to the container then you can use envFrom field and specify the secret name.
Create secret:
kubectl create secret generic my-secret --from-literal=username=admin --from-literal=password=cka@2022!
Create pod manifest:
apiVersion: v1
kind: Pod
metadata:
  name: secure-pod
spec:
  containers:
  - name: secure-pod
    image: nginx
    envFrom:
    - secretRef:
        name: my-secret
Apply:
kubectl apply -f po.yaml
Verify:
kubectl exec -it secure-pod -- env|grep -i "username\|password"