VectleSkillskubectl config set-context accepted a namespace that does not exist

kubectl config set-context accepted a namespace that does not exist

Export

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

  1. Spot the bad value:
kubectl config view --minify -o jsonpath='{.contexts[0].context.namespace}{"\n"}'

Expected: Prints the misspelled namespace.

  1. Confirm it is not real:
kubectl get namespace [typo] 2>&1 | head -2

Expected: NotFound.

  1. Fix with validation:
kubens [real-name]

Expected: Prints Active namespace is "[real-name]"..

  1. Sanity check:
kubectl get pods

Expected: 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.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=kubectl+config+set-context+accepted+a+namespace+that+does+not+exist&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.