Interview Prep/Kubernetes/Configuration, Secrets and storage

How do you inject a Secret as a file with strict permissions?

IntermediateScenarioConfiguration, Secrets and storage
Answer

Situation read → An app needs a TLS key file readable only by its user.

What I'd do →

  1. Mount the Secret as a volume with defaultMode: 0400
  2. Set securityContext.fsGroup and runAsUser so the file is readable by the process
  3. Prefer files over env vars, since env vars leak in /proc and crash dumps
  4. Verify with kubectl exec -- ls -l /etc/tls
  5. Rotate by updating the Secret; mounted files refresh

Why → File mounts have permissions and are updated automatically, env vars have neither.

Interview tip → Mention that mode in YAML is octal in YAML 1.1 but decimal in JSON.

All Kubernetes questions Roadmap: Kubernetes core

More on Configuration, Secrets and storage