
env field. The env field is an array where each item is an object containing:
name:— the environment variable name- either
value:— a literal string, orvalueFrom:— reference to an external source
APP_COLOR as a literal string using value:
envis a list under the container definition.- Each list item must include
name:and eithervalue:orvalueFrom:. - Values provided with
value:are literal strings that appear in the container’s environment.
valueFrom. The most common options are:
configMapKeyRef— reads a key from an existing ConfigMapsecretKeyRef— reads a key from an existing Secret
When using
configMapKeyRef or secretKeyRef, the referenced ConfigMap or Secret must already exist in the same namespace as the Pod. Use kubectl create configmap or kubectl create secret (or your CI/CD tooling) to provision these resources before deploying the Pod.Do not store sensitive data in ConfigMaps. Use Kubernetes Secrets for sensitive information and follow your cluster’s secret management best practices (encryption at rest, RBAC, and restricted access).
- Kubernetes: Configure a Pod to Use a ConfigMap
- Kubernetes: Configure a Pod to Use a Secret
- Kubernetes API Reference: Pod Spec