Supply passwords, API keys and tokens when the Pod runs. Values embedded in code, tracked configuration, ConfigMaps or a Deployment’s environment settings can be exposed.
If a secret was exposed
- Immediately revoke or disable the exposed credential and issue a replacement.
- Remove live values from Deployment manifests, Helm charts and values files, and ConfigMaps.
- Supply the replacement through a Kubernetes
Secretor an external integration. Configure the Pod to read it withsecretKeyRefor a Secret volume.
Recommended approach
Manage values with a Kubernetes Secret or an integration such as External Secrets Operator. Use env.valueFrom.secretKeyRef when the application reads environment variables, or mount a Secret volume when it reads files.
Examples
Before
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
template:
spec:
containers:
- name: app
image: my-app:latest
env:
- name: API_KEY
value: "sk-prod-123456"
After
This excerpt shows only secret injection. Configure the Deployment’s selector, Pod labels and other settings separately. ${REAL_SECRET_VALUE} is a placeholder for a value securely supplied by the deployment tooling; Kubernetes does not automatically substitute an environment variable for it.
yaml
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
stringData:
API_KEY: ${REAL_SECRET_VALUE}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
template:
spec:
containers:
- name: app
image: my-app:latest
env:
- name: API_KEY
valueFrom:
secretKeyRef:
name: app-secret
key: API_KEY
Additional checks
- Check
kubectl describeoutput, application logs and debug scripts for exposed values. Check Helmvalues.yamland ConfigMaps for production values as well. - Base64 values are reversible. Check whether your cluster encrypts Secrets stored in etcd.