Interview Prep/Kubernetes/Pod startup failures

Env vars in the Pod show the literal text `$(DB_HOST):5432` instead of the value.

IntermediateTroubleshootingPod startup failures
Answer

Likely causes → Kubernetes $(VAR) expansion only works for variables defined earlier in the same container's env list. If DB_HOST comes from envFrom defined after, or is defined later in the list, or does not exist, the literal string is kept.

Diagnose →

kubectl exec web-x -- printenv | grep DB_
kubectl get pod web-x -o jsonpath='{.spec.containers[0].env}' | jq

Fix → Define DB_HOST before the variable that uses it:

env:
  - name: DB_HOST
    valueFrom: {configMapKeyRef: {name: app, key: db_host}}
  - name: DB_URL
    value: "postgres://$(DB_HOST):5432/app"

Prevent → Build composite values in the app or in templating, not with runtime expansion chains.

All Kubernetes questions Roadmap: Kubernetes core

More on Pod startup failures