{"record":{"id":"3ecd385cf5b01764","repo":"GoogleContainerTools/skaffold","slug":"getting-k8s-client-w","errorCode":null,"errorMessage":"getting k8s client: %w","messagePattern":"getting k8s client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/watcher.go","lineNumber":84,"sourceCode":"\tw.receivers[receiver] = false\n\tw.receiverLock.Unlock()\n}\n\nfunc (w *podWatcher) Start(ctx context.Context, kubeContext string, namespaces []string) (func(), error) {\n\tif len(w.receivers) == 0 {\n\t\treturn func() {}, errors.New(\"no receiver was registered\")\n\t}\n\n\tvar watchers []watch.Interface\n\tstopWatchers := func() {\n\t\tfor _, w := range watchers {\n\t\t\tw.Stop()\n\t\t}\n\t}\n\n\tkubeclient, err := client.Client(kubeContext)\n\tif err != nil {\n\t\treturn func() {}, fmt.Errorf(\"getting k8s client: %w\", err)\n\t}\n\n\tvar forever int64 = 3600 * 24 * 365 * 100\n\n\tfor _, ns := range namespaces {\n\t\twatcher, err := kubeclient.CoreV1().Pods(ns).Watch(context.Background(), metav1.ListOptions{\n\t\t\tTimeoutSeconds: &forever,\n\t\t})\n\t\tif err != nil {\n\t\t\tstopWatchers()\n\t\t\treturn func() {}, fmt.Errorf(\"initializing pod watcher for %q: %w\", ns, err)\n\t\t}\n\n\t\twatchers = append(watchers, watcher)\n\t\tgo func() {\n\t\t\tl := log.Entry(ctx)\n\t\t\tdefer l.Tracef(\"podWatcher: cease waiting\")\n\t\t\tl.Tracef(\"podWatcher: waiting\")","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/watcher.go#L66-L102","documentation":"The k8s log watcher's Start method obtains a Kubernetes client via client.Client(kubeContext) before watching pods across namespaces; failure is wrapped as 'getting k8s client: %w'. This means a REST config could not be built for the given kube-context — bad kubeconfig, unknown context, or missing credentials.","triggerScenarios":"Starting the pod log watcher (e.g. `skaffold dev`/`run` with log streaming) when client.Client(kubeContext) fails: the kube-context name doesn't exist in kubeconfig, the kubeconfig file is malformed/missing, or in-cluster credentials are absent.","commonSituations":"Wrong kube-context passed via --kube-context; KUBECONFIG pointing at a stale file; minikube/kind cluster deleted so the context's server is gone; running outside the cluster without a kubeconfig when an in-cluster config was expected.","solutions":["List valid contexts with `kubectl config get-contexts` and pass an existing one (or drop --kube-context)","Check KUBECONFIG points at the intended, well-formed kubeconfig file","Recreate/reconnect the cluster (kind create cluster, minikube start) if it was deleted; refresh cloud credentials","Run inside the cluster with proper service-account credentials if in-cluster config is expected"],"exampleFix":"// before\nskaffold dev --kube-context old-cluster\n// after\nskaffold dev --kube-context minikube","handlingStrategy":"validation","validationCode":"// verify the kube-context resolves before starting the watcher\nfunc ensureContext(name string) error {\n    if name == \"\" {\n        return nil // default context\n    }\n    cfg, err := clientcmd.LoadFromFile(os.Getenv(\"KUBECONFIG\"))\n    if err != nil {\n        return err\n    }\n    if _, ok := cfg.Contexts[name]; !ok {\n        return fmt.Errorf(\"kube-context %q not found; have: %v\", name, contextNames(cfg))\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"cleanup, err := watcher.Start(ctx, namespaces, kubeContext)\nif err != nil {\n    var ce *clientcmderr.Error\n    if errors.As(err, &ce) || strings.Contains(err.Error(), \"getting k8s client\") {\n        return fmt.Errorf(\"fix kubeconfig/context (kubectl config get-contexts): %w\", err)\n    }\n    return err\n}\ndefer cleanup()","preventionTips":["Run `kubectl config get-contexts` and match --kube-context to an existing entry","Keep KUBECONFIG well-formed and avoid stale context files","Recreate deleted local clusters before re-running skaffold","Use in-cluster mode only with a mounted, valid service-account token"],"tags":["kubernetes","client-config","kubeconfig"],"backgroundTag":"kubeconfig-context-not-found","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"}