GoogleContainerTools/skaffold · error

getting Kubernetes client: %w

Error message

getting Kubernetes client: %w

What it means

Skaffold could not construct an authenticated Kubernetes clientset for the given kubeContext while preparing to sync files. `kubernetesclient.Client(kubeContext)` loads kubeconfig and builds a clientset; any config or connectivity resolution failure at that step is wrapped here. No pod operations have been attempted yet.

Source

Thrown at pkg/skaffold/sync/sync.go:335

		if err := Perform(ctx, item.Image, item.Delete, s.deleteFileFn, *s.namespaces, s.kubectl.KubeContext); err != nil {
			return fmt.Errorf("deleting files: %w", err)
		}
	}

	return nil
}

func Perform(ctx context.Context, image string, files syncMap, cmdFn func(context.Context, v1.Pod, v1.Container, syncMap) *exec.Cmd, namespaces []string, kubeContext string) error {
	if len(files) == 0 {
		return nil
	}

	errs, ctx := errgroup.WithContext(ctx)

	client, err := kubernetesclient.Client(kubeContext)
	if err != nil {
		return fmt.Errorf("getting Kubernetes client: %w", err)
	}

	numSynced := 0
	for _, ns := range namespaces {
		pods, err := client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{
			FieldSelector: fmt.Sprintf("status.phase=%s", v1.PodRunning),
		})

		if err != nil {
			return fmt.Errorf("getting pods for namespace %q: %w", ns, err)
		}

		if len(pods.Items) == 0 {
			log.Entry(ctx).Warnf("no running pods found in namespace %q", ns)
			continue
		}

		for _, p := range pods.Items {

View on GitHub (pinned to a1189de023)

Solutions

  1. Check `kubectl config get-contexts` and pass a valid context via --kube-context
  2. Verify KUBECONFIG env var points to an existing, readable kubeconfig
  3. Test the context with `kubectl get pods --context <ctx>` to reproduce outside Skaffold
  4. If running in-cluster, ensure the pod has a service account and cluster reachability

Example fix

// before
skaffold dev --kube-context prod-clustr
// after
skaffold dev --kube-context prod-cluster
Defensive patterns

Strategy: validation

Validate before calling

// validate kube context before calling Perform
ctxs, _ := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
    clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()
if _, ok := ctxs.Contexts[kubeContext]; !ok {
    return fmt.Errorf("kube context %q not found in kubeconfig", kubeContext)
}

Type guard

func hasContext(kubeContext string) bool {
    cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
        clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()
    if err != nil { return false }
    _, ok := cfg.Contexts[kubeContext]
    return ok
}

Prevention

When it happens

Trigger: `Perform` (called by sync and anonymous sync workers) calls `kubernetesclient.Client(kubeContext)` and it errors — invalid kubeContext name, missing/unreadable kubeconfig, or inability to resolve the cluster for that context.

Common situations: --kube-context typo; KUBECONFIG pointing to a missing file; context deleted from kubeconfig; running outside a cluster where in-cluster config is expected but unavailable.

Related errors


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