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

  1. List available contexts with `kubectl config get-contexts` and compare with the context Skaffold was given
  2. Run skaffold without --kube-context to use the default current-context, or fix the name in skaffold.yaml
  3. Recreate the cluster/context if it was deleted (kind create cluster / k3d cluster create)
  4. 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

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


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/15b7984fa26f3261. Report an issue: GitHub.