derailed/k9s · error
unable to activate context %q: %w
Error message
unable to activate context %q: %w
What it means
Returned from internal/config/config.go:114 in the implicit-context branch: the context name n was successfully resolved from the kubeconfig, but the subsequent c.K9s.ActivateContext(n) failed. As with error 87 this is a wrapper — the wrapped %w error carries the true cause from the activation pipeline (context lookup, per-context config load via dir.Load, proxy connectivity check).
Source
Thrown at internal/config/config.go:114
setK8sTimeout(flags, d)
} else {
setK8sTimeout(flags, client.DefaultCallTimeoutDuration)
}
}
if isStringSet(flags.Context) {
if _, err := c.K9s.ActivateContext(*flags.Context); err != nil {
return fmt.Errorf("k8sflags. unable to activate context %q: %w", *flags.Context, err)
}
} else {
n, err := cfg.CurrentContextName()
if err != nil {
return fmt.Errorf("unable to retrieve kubeconfig current context %q: %w", n, err)
}
if n != "" {
_, err = c.K9s.ActivateContext(n)
if err != nil {
return fmt.Errorf("unable to activate context %q: %w", n, err)
}
} else {
slog.Debug("No context set, skipping context activation")
}
}
if c.K9s.ActiveContextName() != "" {
slog.Debug("Using active context", slogs.Context, c.K9s.ActiveContextName())
}
var ns string
switch {
case k9sFlags != nil && IsBoolSet(k9sFlags.AllNamespaces):
ns = client.NamespaceAll
c.ResetActiveView()
case isStringSet(flags.Namespace):
ns = *flags.Namespace
c.ResetActiveView()
default:View on GitHub (pinned to 2d3ccc6ba2)
Solutions
- Inspect the full wrapped error chain to identify which activation stage failed
- Check the per-context config: cat ~/.local/share/k9s/clusters/*/<ctx>.yaml and validate its YAML (or delete it to regenerate defaults)
- If proxy is configured, verify reachability (curl -x <address> https://<api-server>) and fix or remove the address
- Re-run kubectl config use-context <ctx> to normalize kubeconfig state and restart k9s
Example fix
# before k9s # 'unable to activate context "prod": ...' # after: the chain points at the context yaml cat ~/.local/share/k9s/clusters/prod-cluster/prod.yaml rm ~/.local/share/k9s/clusters/prod-cluster/prod.yaml # regenerate defaults k9s
Defensive patterns
Strategy: try-catch
Try / catch
ct, err := k9s.ActivateContext(n)
if err != nil {
var root error = err
for errors.Unwrap(root) != nil {
root = errors.Unwrap(root)
}
switch {
case strings.Contains(root.Error(), "getcontext"):
// context vanished from kubeconfig: re-sync state
case strings.Contains(root.Error(), "yaml load failed"):
// repair or delete per-context yaml
case strings.Contains(root.Error(), "unable to connect"):
// proxy unreachable: fix proxy.address
default:
return root
}
} Prevention
- Pin one k9s version across machines sharing the k9s config directory
- Validate per-context yaml files with yamllint after manual edits
- Keep proxy addresses in DNS names, not IPs, so corporate proxy changes break fewer configs
When it happens
Trigger: Starting with a resolvable current-context whose k9s per-context config is corrupt (contexts/<cluster>/<ctx>.yaml fails to unmarshal), or whose proxy address fails CheckConnectivity when a live connection object already exists, or whose context vanished from the kubeconfig between resolution and activation (race).
Common situations: k9s upgrade leaving old-format per-context yaml; proxy config referencing a dead corporate proxy; kubeconfig rewritten by an SSO tool while k9s boots; leftover k9s state directory from another machine.
Related errors
- set current context failed. %w
- k8sflags. unable to activate context %q: %w
- unable to connect to context %q
- unable to locate associated cluster for context %q: %w
- no active context available
AI-assisted analysis of derailed/k9s@2d3ccc6ba2 (2026-08-15).
Data as JSON: /api/errors/65747b4ac80579ec.
Report an issue: GitHub.