The "deployment not found" error occurs when kubectl cannot locate a Deployment resource. This is usually caused by a namespace mismatch, typo in the deployment name, connected to the wrong cluster, or the deployment was deleted.
When you run kubectl commands on a deployment and get "deployment not found", it means kubectl is looking in the wrong place or the deployment doesn't exist. Kubernetes resources are always scoped to a namespace (default is "default"), and a deployment in one namespace is invisible from another. Additionally, you must be connected to the correct Kubernetes cluster. This error is at the kubectl communication layer—it's not an application error, but rather kubectl or the API server can't find the resource you're asking about.
First, confirm you're connected to the right cluster:
kubectl config current-context
kubectl cluster-info
kubectl config get-contexts # List all available contextsIf wrong, switch context:
kubectl config use-context <correct-context-name>For easier context switching, install kubectx: brew install kubectx or sudo git clone https://github.com/ahmetb/kubectx /opt/kubectx
Search all namespaces:
kubectl get deployments --all-namespaces
kubectl get deploy -A | grep <deployment-name>If found in a different namespace, use -n flag:
kubectl get deployment <name> -n <found-namespace>If deployment isn't in any namespace, it was either never created or deleted.
If deployment is in a specific namespace, you can set it as default:
kubectl config set-context --current --namespace=<namespace>Now subsequent commands default to that namespace. Verify:
kubectl config current-context
kubectl get deployments # Should show deployments in your namespaceFor one-off commands, use -n flag: kubectl get deployment <name> -n <namespace>
Kubernetes names are case-sensitive. Confirm exact spelling:
kubectl get deployments -n <namespace> # Shows all deploymentsCompare with your command. Common typos:
- "myapp" vs "my-app" (hyphen)
- "MyApp" vs "myapp" (case)
- "myapp-deploy" vs "myapp" (suffix)
If you're referencing it in code or scripts, check those strings match exactly.
If you used kubectl run, you may have created a Pod, not a Deployment:
kubectl get pods -n <namespace> | grep <name>To create an actual Deployment:
kubectl create deployment <name> --image=<image:tag>
# or from manifest:
kubectl apply -f deployment.yamlFor kubectl run to create a Deployment (instead of Pod), use --restart=Always (default in older versions): kubectl run <name> --image=<image:tag> --restart=Always
If deploying from a manifest, validate it:
kubectl apply -f deployment.yaml --dry-run=clientThis shows validation errors without applying. Common issues:
- Incorrect indentation
- Wrong apiVersion (should be "apps/v1" for Deployments)
- Missing required fields (name, spec, containers)
- Invalid resource names (must start with letter, no special chars)
Fix errors and retry:
kubectl apply -f deployment.yamlIf namespace doesn't exist:
kubectl get namespacesCreate if missing:
kubectl create namespace <namespace-name>Then deploy to it:
kubectl apply -f deployment.yaml -n <namespace-name>Or set it in the manifest:
metadata:
name: myapp
namespace: myapp-ns # Explicitly set namespaceView recent changes:
kubectl describe namespace <namespace> # Shows recent events
kubectl get events -n <namespace> --sort-by='.lastTimestamp' # Recent eventsIf you deleted it accidentally, restore from backup or redeploy. If deleted by automated cleanup (e.g., CI/CD tear-down), reapply the manifest:
kubectl apply -f deployment.yamlFor easier management, install helper tools:
- kubectx: Switch between clusters
kubectx <context-name>- kubens: Switch between namespaces
kubens <namespace>These are faster than typing full kubectl commands. Find them at https://github.com/ahmetb/kubectx
In multi-cluster setups, context confusion is very common—use kubectx/kubens to simplify switching. For GitOps deployments (ArgoCD, Flux), verify the namespace in the Application/HelmRelease resource matches your deployment namespace. In CI/CD pipelines, ensure the kubeconfig context points to the correct cluster; mismatches often occur during multi-environment deployments. When using kubectl from containers, ensure kubeconfig is mounted at the correct path: kubectl --kubeconfig=/path/to/config get deploy. For API group mismatches, use kubectl api-resources to verify the correct apiVersion. Some cloud providers use vendor-specific context naming conventions (e.g., AWS uses "arn:aws:eks:..." format).
Service port already allocated
How to fix "Service port already allocated" in Kubernetes
minimum cpu usage per Container
How to fix "minimum cpu usage per Container" in Kubernetes
Failed to connect to server: connection refused (HTTP/2)
How to fix "HTTP/2 connection refused" error in Kubernetes
No subnets found for EKS cluster
How to fix "eks subnet not found" in Kubernetes
missing request for cpu in container
How to fix "missing request for cpu in container" in Kubernetes HPA