GoogleContainerTools/skaffold · error
unable to get current kubernetes context: %w
Error message
unable to get current kubernetes context: %w
What it means
getCurrentContext looks up currentCfg.Contexts[i.kubeContext] after loading the kubeconfig. This error is returned when the configured context name is not present in the kubeconfig. Note the wrapped err is nil at this point, so the message effectively reports only the missing context — the real cause is a context name mismatch between Skaffold's kubeContext and the kubeconfig.
Source
Thrown at pkg/skaffold/kubernetes/loader/load.go:188
func findKnownImages(ctx context.Context, cli *kubectl.CLI) ([]string, error) {
nodeGetOut, err := cli.RunOut(ctx, "get", "nodes", `-ojsonpath={@.items[*].status.images[*].names[*]}`)
if err != nil {
return nil, fmt.Errorf("unable to inspect the nodes: %w", err)
}
knownImages := strings.Split(string(nodeGetOut), " ")
return knownImages, nil
}
func (i *ImageLoader) getCurrentContext() (*api.Context, error) {
currentCfg, err := kubectx.CurrentConfig()
if err != nil {
return nil, fmt.Errorf("unable to get kubernetes config: %w", err)
}
currentContext, present := currentCfg.Contexts[i.kubeContext]
if !present {
return nil, fmt.Errorf("unable to get current kubernetes context: %w", err)
}
return currentContext, nil
}
View on GitHub (pinned to a1189de023)
Solutions
- List available contexts with `kubectl config get-contexts` and compare with the context Skaffold was given
- Run skaffold without --kube-context to use the default current-context, or fix the name in skaffold.yaml
- Recreate the cluster/context if it was deleted (kind create cluster / k3d cluster create)
- Check KUBECONFIG: the context may exist in a different file that is not currently loaded
Example fix
// before: skaffold.yaml referencing a deleted context deploy: kubeContext: kind-stale // after deploy: kubeContext: kind-kind # per `kubectl config get-contexts`
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the context exists before running skaffold
out, err := exec.Command("kubectl", "config", "get-contexts", "-o", "name").Output()
if err != nil || !slices.Contains(strings.Fields(string(out)), wantedContext) {
return fmt.Errorf("context %q not in kubeconfig; pick from: %s", wantedContext, out)
} Try / catch
err := loader.LoadImages(ctx, out, artifacts)
if err != nil {
if strings.Contains(err.Error(), "unable to get current kubernetes context") {
// fallback to default context
return runWithDefaultContext(ctx, artifacts)
}
return err
} Prevention
- Run `kubectl config get-contexts` and copy names exactly — avoid typos in --kube-context
- Remove stale --kube-context flags / deploy.kubeContext after deleting clusters
- Verify which kubeconfig file is loaded (KUBECONFIG) when a known-good context is 'missing'
When it happens
Trigger: LoadImages calls getCurrentContext with i.kubeContext set (from --kube-context or skaffold config) and that name does not exist in the loaded kubeconfig's contexts map.
Common situations: Typo in --kube-context or in skaffold.yaml's deploy.kubeContext; cluster was deleted so its context was removed; context renamed (e.g. kind-kind vs kind, k3d cluster renamed); kubeconfig loaded from a different file than expected (KUBECONFIG).
Related errors
- getting k8s configuration: %w
- unable to get kubernetes config: %w
- getting current cluster context: %w
- action %v not found for k8s execution mode
- getting Kubernetes client: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/15b7984fa26f3261.
Report an issue: GitHub.