Bird
0
0

You want to mount multiple keys from a Secret named config-secret as environment variables in a Pod. Which is the best way to do this efficiently?

hard📝 Best Practice Q15 of 15
Kubernetes - Secrets
You want to mount multiple keys from a Secret named config-secret as environment variables in a Pod. Which is the best way to do this efficiently?
AMount the Secret as a volume and read files inside the container
BList each key separately under <code>env</code> with individual <code>valueFrom.secretKeyRef</code> entries
CCreate multiple Secrets, one per key, and reference each in <code>env</code>
DEncode all keys into one string and store as a single Secret key
Step-by-Step Solution
Solution:
  1. Step 1: Understand environment variable mapping from Secrets

    You can map each Secret key to an environment variable by listing them separately under env with valueFrom.secretKeyRef.
  2. Step 2: Compare alternatives

    Mounting as volume is valid but not environment variables. Multiple Secrets or encoding keys complicate management.
  3. Final Answer:

    List each key separately under env with individual valueFrom.secretKeyRef entries -> Option B
  4. Quick Check:

    Map each key to env var individually = A [OK]
Quick Trick: Map each Secret key individually in env list [OK]
Common Mistakes:
  • Mounting Secret as volume when env vars needed
  • Creating many Secrets instead of one
  • Combining keys into one encoded string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes