{"record":{"id":"c4d0f8012758eaff","repo":"GoogleContainerTools/skaffold","slug":"unable-to-connect-to-kubernetes-w-c4d0f8","errorCode":null,"errorMessage":"unable to connect to Kubernetes: %w","messagePattern":"unable to connect to Kubernetes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/skaffold/verify/k8sjob/verify.go","lineNumber":126,"sourceCode":"\tv.localImages = images\n}\n\nfunc (v *Verifier) TrackBuildArtifacts(artifacts []graph.Artifact) {\n\tv.logger.RegisterArtifacts(artifacts)\n}\n\n// Verify executes specified artifacts by creating kubernetes Jobs for each image\n// in the specified kubernetes cluster, executing them, and waiting for execution to complete.\nfunc (v *Verifier) Verify(ctx context.Context, out io.Writer, allbuilds []graph.Artifact) error {\n\tvar (\n\t\tchildCtx context.Context\n\t\tendTrace func(...trace.SpanEndOption)\n\t\twg       sync.WaitGroup\n\t)\n\n\t// TODO(aaron-prindle) add trace info\n\tif err := kubernetes.FailIfClusterIsNotReachable(v.kubectl.KubeContext); err != nil {\n\t\treturn fmt.Errorf(\"unable to connect to Kubernetes: %w\", err)\n\t}\n\n\tchildCtx, endTrace = instrumentation.StartTrace(ctx, \"Verify_LoadImages\")\n\tif err := v.imageLoader.LoadImages(childCtx, out, v.localImages, v.localImages, v.localImages); err != nil {\n\t\tendTrace(instrumentation.TraceEndError(err))\n\t\treturn err\n\t}\n\tendTrace()\n\n\tbuilds := []graph.Artifact{}\n\tconst maxWorkers = math.MaxInt64\n\ts := semgroup.NewGroup(context.Background(), maxWorkers)\n\n\tfor _, tc := range v.cfg {\n\t\tfoundArtifact := false\n\t\tnTC := *tc\n\n\t\tfor _, b := range allbuilds {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/verify/k8sjob/verify.go#L108-L144","documentation":"The Kubernetes-cluster Job verifier preflight-checks that the target cluster is reachable before doing any work (loading images, creating jobs). `kubernetes.FailIfClusterIsNotReachable` failed, and the underlying connectivity error is wrapped with this message so the user knows the whole verify step cannot talk to the configured Kubernetes cluster.","triggerScenarios":"Calling Verify (pkg/skaffold/verify/k8sjob) with a kubeContext whose API server is unreachable: wrong kubeconfig context, cluster down, no network/VPN, expired credentials, or a misconfigured `--kube-context` / kubectl context in skaffold.yaml.","commonSituations":"Developer switched kubectl contexts and forgot; remote cluster endpoint changed (EKS/GKE token or IP rot); VPN disconnected; KUBECONFIG env var pointing at a stale file; apiserver temporarily down during maintenance.","solutions":["Verify connectivity: `kubectl --context <ctx> cluster-info` and fix kubeconfig/credentials","Check KUBECONFIG points at the right file and the context/cluster/server URL is correct","Reconnect VPN / fix network access to the API server endpoint","Re-authenticate (e.g. `aws eks update-kubeconfig`, `gcloud container clusters get-credentials`)","Confirm the cluster is actually running and not paused/deleted"],"exampleFix":"// before\nskaffold verify --kube-context stale-context   # unable to connect\n// after\nkubectl config use-context my-cluster\naws eks update-kubeconfig --name my-cluster\nskaffold verify","handlingStrategy":"validation","validationCode":"// preflight before skaffold verify\nimport \"k8s.io/client-go/tools/clientcmd\"\nfunc clusterReachable(kubeContext string) error {\n    cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(\n        clientcmd.NewDefaultClientConfigLoadingRules(),\n        &clientcmd.ConfigOverrides{CurrentContext: kubeContext}).ClientConfig()\n    if err != nil { return err }\n    return clientset.NewForConfigOrDie(cfg).Discovery().ServerVersion()\n}","typeGuard":"func contextExists(kubeContext string) bool {\n    cfg, _ := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(\n        clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()\n    _, ok := cfg.Contexts[kubeContext]\n    return ok\n}","tryCatchPattern":"if err := verifier.Verify(ctx, out); err != nil {\n    if strings.Contains(err.Error(), \"unable to connect to Kubernetes\") {\n        // surface `kubectl cluster-info` guidance to the user\n    }\n}","preventionTips":["Run `kubectl cluster-info` with the same --kube-context before verify","Keep kubeconfig credentials fresh (re-run cloud get-credentials/update-kubeconfig)","Check VPN/network before CI verify steps","Pin the context explicitly instead of relying on the current context"],"tags":["kubernetes","connectivity","kubeconfig"],"backgroundTag":"kubernetes-cluster-unreachable","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}