kubectl "Error from server (NotFound)" on deploy in CI
NotFound means the API server has no object matching what you asked for. In CI this is usually a namespace that was never created, a typo in a name, or operating on a resource that was already deleted.
What this error means
A kubectl get/apply/rollout step returns "Error from server (NotFound)", naming the missing object or namespace.
Error from server (NotFound): namespaces "staging" not found
# or:
Error from server (NotFound): deployments.apps "api" not foundCommon causes
Namespace not created
The deploy targets a namespace that the pipeline never created.
Wrong resource name
A typo in the deployment/service name does not match any existing object.
Acting on an already-deleted resource
A rollout status or delete runs against something a prior step removed.
How to fix it
Create the namespace before applying
kubectl create namespace staging --dry-run=client -o yaml | kubectl apply -f -Verify names and existence
- List the resources to confirm the exact name (
kubectl get deploy -n <ns>). - Ensure prerequisite objects are applied before commands that reference them.
- Order the pipeline so creation precedes status/rollout checks.
How to prevent it
- Create namespaces idempotently at the start of the deploy.
- Reference resources by names that exist in the manifests applied first.
- Use
--ignore-not-foundfor cleanup steps that may run on absent objects.