Skip to content
Latchkey

kubectl "Error from server (NotFound)" - Fix Missing Objects in CI

kubectl asked the API server to operate on a named object that does not exist in the targeted namespace. The resource type is known - this specific instance is simply not there.

What this error means

kubectl get/delete/patch/rollout fails with Error from server (NotFound): <kind> "<name>" not found. Unlike "no resource type", the kind is valid; the named object is missing or you are looking in the wrong namespace.

kubectl output
Error from server (NotFound): deployments.apps "api" not found

Common causes

Wrong namespace

The object lives in another namespace, but the command ran without -n (defaulting to default) or against the wrong one. Namespaced lookups only see the targeted namespace.

Object never created or already deleted

A delete/patch step assumes the object exists, but a prior step never created it (or already removed it). Misordered CI steps and re-runs cause this.

How to fix it

Confirm the namespace and the object

List across namespaces to find where (and whether) it exists.

Terminal
kubectl get deploy api -A
kubectl get deploy -n <ns>

Make destructive steps tolerate absence

  1. Target the correct namespace explicitly with -n on every command.
  2. For idempotent cleanup, add --ignore-not-found=true to deletes.
  3. Order CI so the object is created before any step references it.
Terminal
kubectl delete deploy api -n prod --ignore-not-found=true

How to prevent it

  • Pass -n <namespace> explicitly; never rely on the default namespace in CI.
  • Use --ignore-not-found=true for cleanup steps that may run before creation.
  • Sequence create-before-use across pipeline stages.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →