This error occurs when kubectl cannot locate the specified context in your kubeconfig file. It commonly happens when switching between clusters, after deleting a context, or due to kubeconfig file mismatches.
The 'context not found' error means that kubectl is looking for a Kubernetes context (a named cluster-user-namespace combination) that doesn't exist in your kubeconfig file. A context is a configuration entry that combines three pieces of information: the cluster API server address, user credentials, and a default namespace. When kubectl tries to use a context—either because you set it as current or explicitly requested it—it searches your kubeconfig file(s) and fails if that context name is not defined. This typically happens when the current-context setting points to a context that has been deleted, when you try to use a context that was created in a different kubeconfig file, or when the KUBECONFIG environment variable isn't pointing to the file(s) containing your contexts. Kubeconfig files are YAML documents that store all your Kubernetes cluster access configurations. If your kubeconfig setup is fragmented across multiple files or if you've recently deleted a context, kubectl may be unable to find the context you're trying to use.
See what contexts actually exist in your kubeconfig files:
kubectl config get-contextsThis outputs all contexts across your kubeconfig file(s) and shows which one is currently active (marked with an asterisk). If the context you need is not in this list, it either doesn't exist or is in a kubeconfig file that kubectl isn't reading.
View the context that kubectl is currently trying to use:
kubectl config current-contextIf this returns a context name that doesn't appear in the get-contexts output, the current-context is set to a non-existent context.
Check if you have a custom KUBECONFIG variable set:
echo $KUBECONFIGIf it's empty, kubectl is using ~/.kube/config. If it's set, verify the file(s) exist:
ls -la $KUBECONFIGOn Linux/Mac, multiple files are colon-delimited:
export KUBECONFIG=/path/to/config1:/path/to/config2Inspect the complete kubeconfig to see all clusters, users, and contexts:
kubectl config viewOr to see the flattened version (useful if you have multiple kubeconfig files):
kubectl config view --flattenLook for a contexts: section listing all contexts. Verify that the context you want to use is defined with a cluster and user.
If the context doesn't exist, create it:
kubectl config set-context my-cluster --cluster=my-cluster --user=my-user --namespace=defaultIf the context exists but isn't active, switch to it:
kubectl config use-context my-clusterVerify the switch worked:
kubectl config current-contextIf you created a context with a specific kubeconfig file using the --kubeconfig flag, ensure kubectl can access it:
export KUBECONFIG=$HOME/.kube/config:/path/to/other/config
kubectl config use-context my-contextTo make this permanent, add it to your shell profile (~/.bashrc, ~/.zshrc):
echo 'export KUBECONFIG=$HOME/.kube/config:/path/to/config' >> ~/.bashrc
source ~/.bashrcVerify the context is now accessible:
kubectl config get-contextsUnderstanding kubeconfig structure is essential for managing multiple Kubernetes clusters. A context is a triple of (cluster, user, namespace), and all three must exist in the kubeconfig for the context to work.
When using tools like Kind or Minikube, they automatically generate kubeconfig entries in their own locations. If you merge multiple kubeconfig files using KUBECONFIG, kubectl applies merge rules: the first file to define a value wins.
For security, only trust kubeconfig files from known sources—a malicious kubeconfig can expose credentials or execute code.
When troubleshooting in CI/CD environments, verify that the kubeconfig is correctly mounted or injected into the build container, as file paths may differ from local development.
Some tools use service account tokens instead of static kubeconfig files; in those cases, the error may indicate the service account lacks necessary RBAC permissions rather than a missing context.
No subnets found for EKS cluster
How to fix "eks subnet not found" in Kubernetes
unable to compute replica count
How to fix "unable to compute replica count" in Kubernetes HPA
default backend - 404
How to fix "default backend - 404" in Kubernetes Ingress
serviceaccount cannot list resource
How to fix "serviceaccount cannot list resource" in Kubernetes
must specify requests.cpu, requests.memory
How to fix "must specify requests.cpu, requests.memory" in Kubernetes