{"record":{"id":"9ec38704cf176ad3","repo":"GoogleContainerTools/skaffold","slug":"error-getting-kubernetes-dynamic-client-w","errorCode":null,"errorMessage":"error getting Kubernetes dynamic client: %w","messagePattern":"error getting Kubernetes dynamic client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/deploy/label/labels.go","lineNumber":54,"sourceCode":"\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log\"\n)\n\n// retry 3 times to give the object time to propagate to the API server\nconst (\n\ttries     = 3\n\tsleeptime = 300 * time.Millisecond\n)\n\n// Apply applies all provided labels to the created Kubernetes resources\nfunc Apply(ctx context.Context, labels map[string]string, results []deploy.Artifact, kubeContext string) error {\n\tif len(labels) == 0 {\n\t\treturn nil\n\t}\n\n\t// use the kubectl client to update all k8s objects with a skaffold watermark\n\tdynClient, err := kubernetesclient.DynamicClient(kubeContext)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting Kubernetes dynamic client: %w\", err)\n\t}\n\n\tclient, err := kubernetesclient.Client(kubeContext)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting Kubernetes client: %w\", err)\n\t}\n\n\tfor _, res := range results {\n\t\terr = nil\n\t\tfor i := 0; i < tries; i++ {\n\t\t\tif err = updateRuntimeObject(ctx, dynClient, client.Discovery(), labels, res, kubeContext); err == nil {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\ttime.Sleep(sleeptime)\n\t\t}\n\t\tif err != nil {\n\t\t\tlog.Entry(ctx).Warnf(\"error adding label to runtime object: %s\", err.Error())\n\t\t}","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/deploy/label/labels.go#L36-L72","documentation":"Skaffold's deploy labeling step applies skaffold watermark labels to all deployed Kubernetes objects using the dynamic client. This error wraps any failure from kubernetesclient.DynamicClient(kubeContext), which builds a dynamic.Interface from the kubeconfig for the given context. It means the dynamic Kubernetes client could not be constructed, almost always because the kubeconfig is missing, malformed, or references an unknown context.","triggerScenarios":"Apply() is called after a deploy with a kubeContext that does not exist in kubeconfig; KUBECONFIG env var points to a missing or unparseable file; kubeconfig YAML is invalid; clientcmd fails to build a RESTConfig for the context.","commonSituations":"CI environments with no ~/.kube/config; users switching clusters and removing a context; KUBECONFIG pointing at a stale path; malformed kubeconfig after manual edits.","solutions":["Verify the kubeContext exists: run `kubectl config get-contexts` and use one of the listed names","Check KUBECONFIG points to a valid file and `kubectl config view` parses without error","Regenerate kubeconfig (e.g. re-login with your cloud CLI: gcloud, aws eks update-kubeconfig, az aks get-credentials)","If running in-cluster, ensure a ServiceAccount token is mounted and the context is set correctly"],"exampleFix":"// before\nskaffold deploy --kubeconfig /stale/path/config\n// after\nexport KUBECONFIG=$HOME/.kube/config\nskaffold deploy --kubeconfig $HOME/.kube/config","handlingStrategy":"validation","validationCode":"out, err := exec.Command(\"kubectl\", \"config\", \"get-contexts\").CombinedOutput()\nif err != nil || !strings.Contains(string(out), kubeContext) {\n    return fmt.Errorf(\"kubeContext %q not found in kubeconfig: %s\", kubeContext, out)\n}","typeGuard":null,"tryCatchPattern":"if _, err := kubernetesclient.DynamicClient(kubeContext); err != nil {\n    log.Fatalf(\"cannot build dynamic client for context %q: %v — check KUBECONFIG and context name\", kubeContext, err)\n}","preventionTips":["Verify the context exists with kubectl config get-contexts before deploying","Pin KUBECONFIG explicitly in CI instead of relying on defaults","Re-authenticate cloud credentials before pipelines","Validate kubeconfig YAML after manual edits"],"tags":["kubernetes","kubeconfig","client-init"],"backgroundTag":"invalid-kubeconfig","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"}