{"record":{"id":"15b7984fa26f3261","repo":"GoogleContainerTools/skaffold","slug":"unable-to-get-current-kubernetes-context-w","errorCode":null,"errorMessage":"unable to get current kubernetes context: %w","messagePattern":"unable to get current kubernetes context: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/loader/load.go","lineNumber":188,"sourceCode":"func findKnownImages(ctx context.Context, cli *kubectl.CLI) ([]string, error) {\n\tnodeGetOut, err := cli.RunOut(ctx, \"get\", \"nodes\", `-ojsonpath={@.items[*].status.images[*].names[*]}`)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to inspect the nodes: %w\", err)\n\t}\n\n\tknownImages := strings.Split(string(nodeGetOut), \" \")\n\treturn knownImages, nil\n}\n\nfunc (i *ImageLoader) getCurrentContext() (*api.Context, error) {\n\tcurrentCfg, err := kubectx.CurrentConfig()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to get kubernetes config: %w\", err)\n\t}\n\n\tcurrentContext, present := currentCfg.Contexts[i.kubeContext]\n\tif !present {\n\t\treturn nil, fmt.Errorf(\"unable to get current kubernetes context: %w\", err)\n\t}\n\treturn currentContext, nil\n}\n","sourceCodeStart":170,"sourceCodeEnd":192,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/loader/load.go#L170-L192","documentation":"getCurrentContext looks up currentCfg.Contexts[i.kubeContext] after loading the kubeconfig. This error is returned when the configured context name is not present in the kubeconfig. Note the wrapped err is nil at this point, so the message effectively reports only the missing context — the real cause is a context name mismatch between Skaffold's kubeContext and the kubeconfig.","triggerScenarios":"LoadImages calls getCurrentContext with i.kubeContext set (from --kube-context or skaffold config) and that name does not exist in the loaded kubeconfig's contexts map.","commonSituations":"Typo in --kube-context or in skaffold.yaml's deploy.kubeContext; cluster was deleted so its context was removed; context renamed (e.g. kind-kind vs kind, k3d cluster renamed); kubeconfig loaded from a different file than expected (KUBECONFIG).","solutions":["List available contexts with `kubectl config get-contexts` and compare with the context Skaffold was given","Run skaffold without --kube-context to use the default current-context, or fix the name in skaffold.yaml","Recreate the cluster/context if it was deleted (kind create cluster / k3d cluster create)","Check KUBECONFIG: the context may exist in a different file that is not currently loaded"],"exampleFix":"// before: skaffold.yaml referencing a deleted context\ndeploy:\n  kubeContext: kind-stale\n// after\ndeploy:\n  kubeContext: kind-kind  # per `kubectl config get-contexts`","handlingStrategy":"validation","validationCode":"// Confirm the context exists before running skaffold\nout, err := exec.Command(\"kubectl\", \"config\", \"get-contexts\", \"-o\", \"name\").Output()\nif err != nil || !slices.Contains(strings.Fields(string(out)), wantedContext) {\n    return fmt.Errorf(\"context %q not in kubeconfig; pick from: %s\", wantedContext, out)\n}","typeGuard":null,"tryCatchPattern":"err := loader.LoadImages(ctx, out, artifacts)\nif err != nil {\n    if strings.Contains(err.Error(), \"unable to get current kubernetes context\") {\n        // fallback to default context\n        return runWithDefaultContext(ctx, artifacts)\n    }\n    return err\n}","preventionTips":["Run `kubectl config get-contexts` and copy names exactly — avoid typos in --kube-context","Remove stale --kube-context flags / deploy.kubeContext after deleting clusters","Verify which kubeconfig file is loaded (KUBECONFIG) when a known-good context is 'missing'"],"tags":["kubernetes","kubeconfig","context","configuration"],"backgroundTag":"kube-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"}