kubectx: warning: kubeconfig file not found
Routes kubectx missing-kubeconfig warnings. Use when kubectx prints warning: kubeconfig file not found and lists nothing. Not for contexts that exist but are misspelled.
kubectx is looking at a KUBECONFIG path that does not exist - the env var points at a deleted file, or HOME changed (sudo, containers) and ~/.kube/config is not there. Check echo $KUBECONFIG and ls ~/.kube/config. Point KUBECONFIG at the real file or regenerate the config, and kubectx lists contexts again.
The error
warning: kubeconfig file not foundWhat to do
- Find what kubectx is looking at:
echo "KUBECONFIG=$KUBECONFIG"
ls -la ~/.kube/configExpected: Shows a missing file or an env var pointing nowhere.
- If the file exists elsewhere, point at it:
export KUBECONFIG=/path/to/config
kubectxExpected: Contexts list normally.
- If no kubeconfig exists at all, generate one from your provider (aws eks update-kubeconfig, gcloud container clusters get-credentials, az aks get-credentials).
Expected: Config written; warning gone.
When this applies
- the exact warning: kubeconfig file not found message
- sudo or containers where HOME differs
- KUBECONFIG env var pointing at a moved or deleted file
When it does NOT apply
- context name typos (config exists, name is wrong)
- permission denied reading the file (different error)
Works with
kubectx (ahmetb/kubectx)
kubectl errors about missing configuration on the same machine
Same missing-file root cause. Fix the file or the env var once and both tools work.
Why it happens
kubectx reads the same kubeconfig resolution as kubectl: $KUBECONFIG first, then ~/.kube/config. When neither resolves to a file, listing warns instead of crashing.
Edge cases
- A KUBECONFIG with several colon-separated paths warns only if none exist; a typo in one path is silently ignored.
- kubectx never creates the file - only provider CLIs or manual setup do.
Resolved from
gh:nao1215/atago (e2e kubectx behavior spec) - https://github.com/nao1215/atago/blob/HEAD/doc/e2e/kubectx.md
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.