{"record":{"id":"0ae42f8af3330484","repo":"kubernetes/kops","slug":"getting-rest-config-w","errorCode":null,"errorMessage":"getting rest config: %w","messagePattern":"getting rest config: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/delete_instance.go","lineNumber":177,"sourceCode":"}\n\nfunc RunDeleteInstance(ctx context.Context, f *util.Factory, out io.Writer, options *DeleteInstanceOptions) error {\n\tclientSet, err := f.KopsClient()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tcluster, err := GetCluster(ctx, f, options.ClusterName)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar k8sClient kubernetes.Interface\n\tvar restConfig *rest.Config\n\tif !options.CloudOnly {\n\t\trestConfig, err = f.RESTConfig(ctx, cluster, options.CreateKubecfgOptions)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"getting rest config: %w\", err)\n\t\t}\n\n\t\thttpClient, err := f.HTTPClient(restConfig)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"getting http client: %w\", err)\n\t\t}\n\n\t\tk8sClient, err = kubernetes.NewForConfigAndClient(restConfig, httpClient)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot build kube client: %w\", err)\n\t\t}\n\t}\n\n\tvar nodes []v1.Node\n\tif !options.CloudOnly {\n\t\tnodes, err = getNodes(ctx, k8sClient, true)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/delete_instance.go#L159-L195","documentation":"When not running with --cloud-only, RunDeleteInstance needs an in-cluster Kubernetes API client to drain/delete the node. It obtains the REST config via f.RESTConfig(ctx, cluster, options.CreateKubecfgOptions); failure (missing or unusable kubeconfig, unreachable cluster admin endpoint) is wrapped as \"getting rest config: ...\".","triggerScenarios":"f.RESTConfig returns an error: no kubeconfig at the default path, context for the cluster absent, invalid credentials, or kOps cannot build a config for the cluster's API endpoint.","commonSituations":"KUBECONFIG pointing to an empty file; deleting an instance of a cluster whose admin kubeconfig was never fetched (`kops export kubeconfig`); running from outside the VPC where the API server is unreachable.","solutions":["Run `kops export kubeconfig <cluster> --admin` (or `kops export kubecfg`) to generate a valid kubeconfig, then retry.","Verify KUBECONFIG points at the right file and context exists: `kubectl config get-contexts`.","If you cannot reach the cluster's API, re-run with `--cloud-only` to skip Kubernetes interaction."],"exampleFix":"// before\nkops delete instance i-0abc123 --name cluster.example.com\n// after\nkops export kubeconfig cluster.example.com --admin\nkops delete instance i-0abc123 --name cluster.example.com  # or add --cloud-only","handlingStrategy":"validation","validationCode":"cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(\n    clientcmd.NewDefaultClientConfigLoadingRules(), nil).ClientConfig()\nif err != nil {\n    return fmt.Errorf(\"run `kops export kubeconfig <cluster> --admin` first: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := run(...); err != nil && strings.Contains(err.Error(), \"getting rest config\") {\n    // regenerate kubeconfig via `kops export kubeconfig` or fall back to --cloud-only\n}","preventionTips":["Export the admin kubeconfig before node-level operations.","Verify kubectl connectivity (`kubectl get nodes`) before deleting instances.","Use --cloud-only when the API server is unreachable from your network."],"tags":["kubernetes","kubeconfig","api-client"],"backgroundTag":"kubeconfig-invalid-or-missing","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}