kubectl config set-context accepted a namespace that does not exist
Routes silent bad-namespace config writes. Use when a context points at a nonexistent namespace because kubectl config set-context never validates. Not for kubens validation failures.
kubectl config set-context --namespace writes whatever string you give it - no API check. One typo and every later kubectl command silently targets a namespace that is not there, returning empty lists instead of errors. Catch it with kubectl config view --minify, fix it with kubens [real-name] (which validates), and prefer kubens for namespace switches going forward.
The error
Context "[ctx]" modified. (but the namespace "[typo]" does not exist - every kubectl call now targets it)What to do
- Spot the bad value:
kubectl config view --minify -o jsonpath='{.contexts[0].context.namespace}{"\n"}'Expected: Prints the misspelled namespace.
- Confirm it is not real:
kubectl get namespace [typo] 2>&1 | head -2Expected: NotFound.
- Fix with validation:
kubens [real-name] Expected: Prints Active namespace is "[real-name]"..
- Sanity check:
kubectl get podsExpected: Shows the real pods instead of an empty list.
When this applies
- kubectl returning empty lists right after a set-context --namespace
- typos in --namespace values
- scripts that write namespace values without checking
When it does NOT apply
- kubens refusing a name (that IS validation working)
- namespaces that exist but are empty
Works with
kubectl; kubens for the validated fix
helm/k9s showing nothing after a context edit
Same dangling namespace in the shared kubeconfig. Fix it once and every tool recovers.
Why it happens
The kubeconfig namespace field is free text; set-context performs no read against the cluster. kubens exists partly to close that gap by validating first.
Edge cases
- Automation should run kubectl get namespace [name] before writing it into a context.
- A namespace deleted after being set produces the same silent-empty symptom - re-validate on failure.
Resolved from
gh:ahmetb/kubectx#83 - https://github.com/ahmetb/kubectx/issues/83
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.