kubernetes/kops · error
cluster not found %q
Error message
cluster not found %q
What it means
buildCredentials fetches the cluster object from the kOps state store to locate its keystore. GetCluster returned nil,nil (no cluster with that name in the state store), so buildCredentials returns this 'cluster not found' error. This means the --cluster name does not match any cluster registered in the configured KOPS_STATE_STORE.
Source
Thrown at pkg/commands/helpers/kubectl_auth.go:240
return nil, fmt.Errorf("no credentials in cached file")
}
return execCredential, nil
}
func buildCredentials(ctx context.Context, f *util.Factory, options *HelperKubectlAuthOptions) (*ExecCredentialStatus, error) {
clientset, err := f.KopsClient()
if err != nil {
return nil, err
}
cluster, err := clientset.GetCluster(ctx, options.ClusterName)
if err != nil {
return nil, err
}
if cluster == nil {
return nil, fmt.Errorf("cluster not found %q", options.ClusterName)
}
keyStore, err := clientset.KeyStore(cluster)
if err != nil {
return nil, fmt.Errorf("unable to get cluster keystore: %v", err)
}
cn := "kubecfg"
user, err := user.Current()
if err != nil || user == nil {
klog.Infof("unable to get user: %v", err)
} else {
cn += "-" + user.Name
}
req := pki.IssueCertRequest{
Signer: fi.CertificateIDCA,
Type: "client",View on GitHub (pinned to 4c8573c808)
Solutions
- Run `kops get clusters` to list valid names and fix the --cluster value.
- Verify KOPS_STATE_STORE points to the bucket containing the cluster.
- Recreate the kubeconfig with `kops export kubecfg <cluster>` if the cluster was deleted or renamed.
Example fix
// before kops helpers kubectl-auth --cluster myclster.example.com // after kops helpers kubectl-auth --cluster mycluster.example.com
Defensive patterns
Strategy: validation
Validate before calling
// verify the cluster exists before invoking the helper
if err := exec.Command("kops", "get", "cluster", clusterName).Run(); err != nil {
return fmt.Errorf("cluster %q not present in KOPS_STATE_STORE=%s", clusterName, os.Getenv("KOPS_STATE_STORE"))
} Prevention
- Verify cluster names with `kops get clusters` before configuring kubeconfig.
- Pin KOPS_STATE_STORE explicitly in profiles/scripts for each environment.
- Refresh kubeconfig after deleting or renaming clusters (`kops export kubecfg`).
When it happens
Trigger: Calling kubectl-auth with --cluster <name> where <name> doesn't exist in the state store: typo in cluster name, wrong KOPS_STATE_STORE (S3 bucket / GCS path) selected, or cluster deleted while kubeconfig still references it.
Common situations: Old kubeconfig after cluster deletion; multiple state stores (prod vs dev buckets) with the same cluster name in only one; renamed cluster; pointing at an empty local state store with KOPS_STATE_STORE=file://....
Related errors
- error creating cluster: %v
- error replacing cluster: %v
- ClusterName is missing
- expected azureblob:// ConfigStore.Base for Azure cluster, go
- error building ConfigBase for cluster: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/2bbc5762cfc9c366.
Report an issue: GitHub.