Kubernetes "namespaces \"<name>\" not found" on deploy in CI - Fix it
kubectl tried to create or operate on resources in a namespace that has not been created. Namespaces are not auto-created on apply, so resources targeting a missing namespace are rejected.
What this error means
kubectl apply -n <name> (or objects with that namespace) fails with Error from server (NotFound): namespaces "<name>" not found.
kubectl
Error from server (NotFound): namespaces "staging" not foundCommon causes
Namespace never created
The target namespace is referenced but no Namespace object was applied first.
Apply ordering
The Namespace and the workloads are in one bundle but the workloads sort ahead of the Namespace.
How to fix it
Create the namespace first
Ensure the namespace exists before applying namespaced resources.
Terminal
kubectl create namespace staging --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f manifests/ -n stagingOrder namespace ahead of workloads
- Include the Namespace object and apply it before dependent resources.
- With kustomize/Helm, ensure the namespace is created in the same release.
- Use
--namespaceconsistently across the pipeline.
How to prevent it
- Always provision the namespace as the first step of a deploy.
- Keep a Namespace manifest in the bundle (or
helm install --create-namespace). - Pin the namespace via a single CI variable.
Related guides
Kubernetes "kubectl rollout: deployment not found" in CI - Fix itFix "error: deployments.apps \"<name>\" not found" from kubectl rollout in CI - the named Deployment does not…
Kubernetes "Error from server (Conflict): operation cannot be fulfilled" in CIFix "Error from server (Conflict): Operation cannot be fulfilled ... object has been modified" in CI - an opt…
Kubernetes "Error from server (Forbidden)" RBAC clusterrole in CI - Fix itFix "Error from server (Forbidden): ... cannot ... " in CI - the authenticated identity is missing the RBAC p…