Config Secrets Volumes
Inject config and storage into pods. Results appear in the same fence: same-line # comments when short, multiline # blocks below the sample when not. Fences are bash, dockerfile, or yaml as appropriate.
Search across all documentation pages
Inject config and storage into pods. Results appear in the same fence: same-line # comments when short, multiline # blocks below the sample when not. Fences are bash, dockerfile, or yaml as appropriate.
Non-secret config data.
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
APP_MODE: prod
# key APP_MODEBase64 opaque secrets (still encrypt at rest in cluster).
apiVersion: v1
kind: Secret
metadata:
name: db
type: Opaque
stringData:
password: s3cret
# stringData auto-encodesLoad all keys as env vars.
envFrom:
- configMapRef:
name: app-config
# APP_MODE=prod in containerMount ConfigMap/Secret/PVC into a path.
volumes:
- name: cfg
configMap: { name: app-config }
containers:
- name: api
volumeMounts:
- name: cfg
mountPath: /config
# /config/APP_MODE fileRequest durable storage.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
# Bound when provisioner succeedsSingle key from ConfigMap/Secret.
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db
key: password
# DB_PASSWORD setMount one key as a file name.
volumeMounts:
- name: cfg
mountPath: /app/config.yaml
subPath: config.yaml
# single file mountEphemeral pod-local volume.
volumes:
- name: tmp
emptyDir: {}
# wiped when pod is removedCombine sources into one volume.
volumes:
- name: all
projected:
sources:
- configMap: { name: app-config }
- secret: { name: db }
# merged mountFile permissions on mounted keys.
configMap:
name: app-config
defaultMode: 0440
# mode 440 filesDo not fail pod if ConfigMap missing.
configMapRef:
name: maybe
optional: true
# pod starts without itImmutable ConfigMap/Secret for cache safety.
immutable: true
# cannot update data in placeCSI driver volume example shape.
volumes:
- name: data
csi:
driver: example.csi.k8s.io
volumeAttributes:
foo: bar
# provisioned via CSINode path mount - avoid in multi-tenant clusters.
volumes:
- name: docker
hostPath:
path: /var/run/docker.sock
# node-specific; security riskDynamic provisioning class name on PVC.
storageClassName: fast-ssd
# selects provisioner parametersStack versions: Kubernetes 1.36.2 · Docker Engine 29.6.1 · Helm 3 · Compose v2 · containerd via CRI
Reviewed by Chris St. John·Last updated Jul 18, 2026