GoogleContainerTools/skaffold · error

unable to get kubernetes config: %w

Error message

unable to get kubernetes config: %w

What it means

getCurrentContext loads the full kubeconfig via kubectx.CurrentConfig() to resolve the Cluster associated with i.kubeContext. This error wraps a failure to read or parse the Kubernetes client configuration — missing, malformed, or unreadable kubeconfig files, or client-go config loading errors.

Source

Thrown at pkg/skaffold/kubernetes/loader/load.go:183

	output.Default.Fprintln(out, "Images loaded in", timeutil.Humanize(time.Since(start)))
	return nil
}

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. Run `kubectl config view` with the same environment to see the parse error
  2. Validate KUBECONFIG points at an existing, readable file: `echo $KUBECONFIG && ls -l $KUBECONFIG`
  3. Regenerate the kubeconfig from your provider (e.g. `kind get kubeconfig-path`, `gcloud container clusters get-credentials`, `k3d kubeconfig get`)
  4. Check YAML syntax of the kubeconfig if it was hand-edited; remove broken entries from merged KUBECONFIG lists

Example fix

// before: KUBECONFIG points to a missing file
export KUBECONFIG=~/.kube/nonexistent
// after
unset KUBECONFIG  # or export KUBECONFIG=~/.kube/config
Defensive patterns

Strategy: validation

Validate before calling

// Validate kubeconfig exists and parses before invoking the loader
path := os.Getenv("KUBECONFIG")
if path == "" { path = filepath.Join(homedir.Get(), ".kube", "config") }
data, err := os.ReadFile(path)
if err != nil {
    return fmt.Errorf("kubeconfig unreadable: %w", err)
}
var cfg map[string]interface{}
if err := yaml.Unmarshal(data, &cfg); err != nil {
    return fmt.Errorf("kubeconfig malformed: %w", err)
}

Try / catch

err := loader.LoadImages(ctx, out, artifacts)
if err != nil {
    if strings.Contains(err.Error(), "unable to get kubernetes config") {
        return fmt.Errorf("fix KUBECONFIG/kubeconfig file first: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: LoadImages calls getCurrentContext before loading into a kind/k3d cluster; kubectx.CurrentConfig() fails because no kubeconfig exists, KUBECONFIG points to an invalid path, or a kubeconfig file contains invalid YAML/schema.

Common situations: Fresh machine with no ~/.kube/config; KUBECONFIG env var referencing a nonexistent or syntactically broken file; permissions issue on the kubeconfig; a partially written kubeconfig after an interrupted cluster provisioning; malformed entries merged from multiple KUBECONFIG files.

Related errors


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