Challenge - 5 Problems
Secrets Env Vars Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of Pod Environment Variable from Secret
Given the following Kubernetes Pod YAML snippet, what will be the output of the command
Pod YAML snippet:
echo $API_KEY inside the container?Pod YAML snippet:
apiVersion: v1
kind: Pod
metadata:
name: secret-env-pod
spec:
containers:
- name: test-container
image: busybox
command: ["sh", "-c", "echo $API_KEY && sleep 3600"]
env:
- name: API_KEY
valueFrom:
secretKeyRef:
name: mysecret
key: api_keyAttempts:
2 left
💡 Hint
Secrets can be referenced as environment variables using valueFrom.secretKeyRef.
✗ Incorrect
Kubernetes allows you to inject Secret values as environment variables using valueFrom.secretKeyRef. The container will have the environment variable API_KEY set to the Secret's 'api_key' value.
❓ Configuration
intermediate2:00remaining
Correct Secret Reference in Pod Spec
Which of the following environment variable configurations correctly injects the Secret key
password from Secret db-secret into the container environment variable DB_PASS?Attempts:
2 left
💡 Hint
Use valueFrom.secretKeyRef to reference Secrets in environment variables.
✗ Incorrect
Option D correctly uses valueFrom.secretKeyRef with the Secret name and key. Option D is invalid syntax. Option D treats the Secret as a string literal. Option D incorrectly uses configMapKeyRef instead of secretKeyRef.
❓ Troubleshoot
advanced2:00remaining
Why is the Secret environment variable empty?
A developer created a Secret named
app-secret with key token. The Pod YAML references it as an environment variable APP_TOKEN using valueFrom.secretKeyRef. However, inside the container, echo $APP_TOKEN prints an empty line. What is the most likely cause?Attempts:
2 left
💡 Hint
Secrets are namespace-scoped and must be in the same namespace as the Pod.
✗ Incorrect
If the Secret is missing or in a different namespace, Kubernetes cannot inject its value, resulting in an empty environment variable. The container image supports env vars by default. Mounting as a volume is not required for env vars. Misspelling the key would cause a different error or empty value but the most common cause is namespace mismatch.
🔀 Workflow
advanced2:00remaining
Steps to Update a Secret Used as Environment Variable
You updated the value of a Kubernetes Secret
api-keys used as an environment variable in a running Pod. What is the correct workflow to apply the new Secret value so the Pod sees the updated environment variable?Attempts:
2 left
💡 Hint
Pods do not automatically reload environment variables from updated Secrets.
✗ Incorrect
Kubernetes does not update environment variables in running containers when Secrets change. The common practice is to update the Secret and then delete the Pod so the controller recreates it with the new Secret values. Manually exporting env vars or patching the Pod does not work. Restarting containers inside a Pod is not supported.
✅ Best Practice
expert2:00remaining
Secure Handling of Secrets as Environment Variables
Which practice is the most secure when using Kubernetes Secrets as environment variables in Pods?
Attempts:
2 left
💡 Hint
Kubernetes Secrets are designed for sensitive data and access control is important.
✗ Incorrect
Option C follows best security practices by using Secrets and controlling access via RBAC. Option C is insecure because ConfigMaps are not encrypted. Option C exposes Secrets in YAML files which can be checked into source control. Option C is insecure and not recommended.