Kubernetes: MountVolume.SetUp failed, secret not found
The kubelet cannot mount a volume because the Secret or ConfigMap is missing, in another namespace, or named differently. Create it, then restart pods.

Introduction & Quick Summary
A pod sits in ContainerCreating and the event list repeats:
Warning FailedMount kubelet MountVolume.SetUp failed for volume "app-config"
: secret "app-config" not foundThe kubelet tried to mount the volume that references Secret app-config, asked the API server for it in the pod's namespace, and got a 404. It will retry with backoff, so the pod is not dead, but it will never start until the object exists at that exact name in that exact namespace.
The four causes worth checking first:
- The Secret does not exist at all, because it is created by a separate manifest that has not applied.
- It exists in another namespace; Secrets are namespaced and a pod can only mount its own.
- The name differs: Helm prefixes release names, Kustomize adds suffixes, and a copied YAML keeps the old name.
- The volume references a key that is missing, which produces a different but related event.
Quick answer: kubectl get secret app-config -n <pod-namespace>. If it is absent, create it in that namespace and the kubelet mounts it on the next retry without recreating the pod. If it exists and the pod still fails, read the next event: the error changes from not found to couldn't find key or permission denied.
Core Mechanics, Signatures & Reproducible Setup
A Secret volume is resolved by the kubelet, not the scheduler. The scheduler only checks that a volume can be satisfied by a node; the kubelet then fetches the Secret through its own API credentials and writes the data into the pod's mount namespace at /var/lib/kubelet/pods/<uid>/volumes/kubernetes.io~secret/<name>.
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
namespace: shop
spec:
replicas: 1
selector:
matchLabels: { app: api }
template:
metadata:
labels: { app: api }
spec:
containers:
- name: api
image: ghcr.io/example/api:1.4.0
volumeMounts:
- name: app-config
mountPath: /etc/api
readOnly: true
volumes:
- name: app-config
secret:
secretName: app-config
defaultMode: 0400
optional: falseReproduce the failure deliberately to see both events in order:
kubectl -n shop create deployment api --image=nginx
kubectl -n shop get pods -w
kubectl -n shop describe pod <pod> | sed -n '/Events/,$p'The event sequence is informative. FailedMount ... not found means the object is missing. FailedMount ... couldn't find key foo in Secret shop/app-config means the object exists and its data does not contain the requested key. FailedMount ... forbidden means the kubelet's access or a policy layer rejects the read.
| Event | Cause |
|---|---|
secret "x" not found | object absent in the pod namespace |
couldn't find key k in Secret ns/x | items or secretKeyRef names a missing key |
configmap "x" not found | same failure for a ConfigMap volume |
is forbidden | admission policy or RBAC blocks the kubelet |
has no such file or directory | mount path conflict with another volume |
Key Comparison Table
| Source | Refreshes in running pod | Namespaced | Best for |
|---|---|---|---|
| Secret volume | yes, on kubelet sync | yes | credentials read as files |
Secret envFrom or env.valueFrom | no, values fixed at start | yes | simple environment configuration |
| ConfigMap volume | yes, on kubelet sync | yes | non-secret configuration files |
| Projected volume | yes | yes | combining Secret, ConfigMap, and token |
| CSI secret store | depends on driver | yes | external vaults, rotation |
The choice changes the failure mode. A volume mount retries forever and reflects updates; environment variables are resolved once at container start, so a missing Secret produces CreateContainerConfigError instead of FailedMount, and a fixed Secret requires a pod restart.
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
1. Check the namespace, not just the name
A Secret in default is invisible to a pod in shop. Describe the pod and read its namespace from the metadata rather than from your current context.
POD=$(kubectl -n shop get pod -l app=api -o jsonpath='{.items[0].metadata.name}')
NS=$(kubectl -n shop get pod "$POD" -o jsonpath='{.metadata.namespace}')
kubectl -n "$NS" get secret app-config
kubectl -n "$NS" get secret app-config -o jsonpath='{.data}' | head -c 200Listing -A and finding the Secret elsewhere confirms the diagnosis immediately.
2. Generated names from Helm and Kustomize
Templates often render {{ .Release.Name }}-config, so the object is shop-prod-config while the volume still says app-config. Reference the same helper in both places.
{{- define "api.secretName" -}}
{{ .Release.Name }}-config
{{- end -}}
volumes:
- name: app-config
secret:
secretName: {{ include "api.secretName" . }}For Kustomize, set namePrefix consistently and let nameReference rewrite the volume field, or the prefix applies to the Secret only.
3. A key inside the Secret is missing
The object exists, so the not found message disappears, and a different event takes its place.
volumes:
- name: app-config
secret:
secretName: app-config
items:
- key: app.yaml # must exist in .data
path: app.yamlVerify the keys before changing the manifest:
kubectl -n shop get secret app-config -o go-template='{{range $k,$v := .data}}{{$k}}{{"\n"}}{{end}}'Remember that stringData is merged into data on write, so keys created with stringData are present under data when read back.
4. optional: true and the stuck pod
optional: true turns a missing Secret into an empty mount instead of an error. That is useful for feature flags and dangerous for credentials, because the container starts and fails later with a confusing configuration error.
volumes:
- name: app-config
secret:
secretName: app-config
optional: trueUse it only when the application can genuinely run with no files at all, and log clearly when the directory is empty.
5. Creating the Secret after the pod
Volume mounts recover automatically: once the Secret exists, the kubelet completes the mount on its next sync, usually within a minute, and the pod proceeds. Environment variables do not recover, because the container spec was already resolved.
kubectl -n shop create secret generic app-config \
--from-file=app.yaml=./config/prod.yaml \
--dry-run=client -o yaml | kubectl apply -f -Applying with kubectl apply rather than create keeps repeated runs idempotent and avoids AlreadyExists errors in automation.
6. Immutable Secrets and rotation
A Secret marked immutable: true cannot be updated; a new value requires a new object and a pod restart. That protects against accidental edits but breaks rotation scripts that patch in place.
apiVersion: v1
kind: Secret
metadata:
name: app-config-v2
namespace: shop
immutable: trueRotate by creating a new name, updating the volume reference, and rolling the deployment. Pods that mounted the old object keep the old files until they are recreated.
Common Compilation/Runtime Mistakes & Version Gotchas
- Editing a Secret and expecting the app to reload. Volume files update, but most applications read configuration once at start. Restart the pods or add a reload trigger.
envFromfor optional credentials. A missing key inenvFromis skipped silently unlessoptionalis set deliberately; the container starts without the variable.- Admission policies. Pod Security Admission and policy engines can deny Secret volumes. The event then says
forbidden, notnot found, and the fix is a policy change rather than a new Secret. - GitOps ordering. Argo CD and Flux apply manifests in waves; a Deployment before its Secret produces a burst of
FailedMountevents that resolve on their own. Sync waves or a dependency hint avoid the noise. - Namespaced defaults.
kubectl create secretwithout-nwrites to the current context namespace, which is the most common way a correct manifest meets an empty namespace.
| Symptom | Cause | Fix |
|---|---|---|
CreateContainerConfigError | missing env source | create Secret or restart pod |
FailedMount repeats every few seconds | object absent | create it in the pod namespace |
| mounts but app cannot read file | defaultMode too restrictive | set mode readable by the container user |
| works in dev, fails in prod | different namespace or prefix | use the same helper for both |
Base64 values are a frequent source of quiet mistakes, so decode a suspicious entry with the Base64 tool before comparing it to the source file, and validate the manifest with the YAML formatter to catch indentation that puts secretName under the wrong key.
The behaviour of Secret volumes, including optional and immutability, is documented in Kubernetes Secrets, and the volume type itself is described under Volumes. Both pages are short and cover the exact fields used above.
Official references
primary documentationThe Kubernetes documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Kubernetes work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Kubernetes guides
All Kubernetes guidesKubernetes 1.35: kubelet will not start on a cgroup v1 node
A 1.35 kubelet refuses a cgroup v1 host, and the removed pod-infra flag stops custom images. Check the kernel command line before the node pool.
Kubernetes: x509 certificate has expired or is not yet valid
kubeadm control plane certificates last one year. Renew them, restart the static pods, refresh kubeconfigs, and alert before the next expiry.
kubectl: metadata.resourceVersion: Invalid value: 0x0
The 0x0 error means an update carried no resourceVersion. Switch to apply or patch, or read the live object first, and keep versions out of Git.
no matches for kind in version: removed APIs and missing CRDs
kubectl cannot map the manifest to an endpoint. Either the API version was removed or the CRD is absent, and discovery tells you which.
More in Kubernetes
All Kubernetes guidesThe guides filed next to this one in Kubernetes, in library order.