kubernetes/kops · error
cluster not found %q
Error message
cluster not found %q
What it means
RunGetInstances in `kops get instances` looks up the target cluster via clientset.GetCluster. In this kops state-store backend, a miss returns (nil, nil), so the command explicitly checks for a nil cluster and throws "cluster not found %q". It means the given cluster name does not correspond to any cluster registered in the configured state store.
Source
Thrown at cmd/kops/get_instances.go:105
opt.CreateKubecfgOptions.AddCommonFlags(cmd.Flags())
return cmd
}
func RunGetInstances(ctx context.Context, f *util.Factory, out io.Writer, options *GetInstancesOptions) error {
clientset, err := f.KopsClient()
if err != nil {
return err
}
cluster, err := clientset.GetCluster(ctx, options.ClusterName)
if err != nil {
return err
}
if cluster == nil {
return fmt.Errorf("cluster not found %q", options.ClusterName)
}
cloud, err := cloudup.BuildCloud(cluster)
if err != nil {
return err
}
restConfig, err := f.RESTConfig(ctx, cluster, options.CreateKubecfgOptions)
if err != nil {
return err
}
httpClient, err := f.HTTPClient(restConfig)
if err != nil {
return err
}
k8sClient, err := kubernetes.NewForConfigAndClient(restConfig, httpClient)View on GitHub (pinned to 4c8573c808)
Solutions
- Run `kops get clusters` (with the same --state flag) to list valid cluster names and copy the exact name
- Verify KOPS_STATE_STORE points to the state store that actually holds the cluster (e.g. s3://your-bucket)
- Set KOPS_CLUSTER_NAME or pass the fully-qualified cluster name to avoid ambiguity
- If the cluster was deleted intentionally, recreate it with `kops create cluster` before listing instances
Example fix
// before kops get instances mycluster // after kops get clusters # confirm exact name kops get instances mycluster.example.com --state s3://correct-bucket
Defensive patterns
Strategy: validation
Validate before calling
name="$1"
kops get clusters --state "${KOPS_STATE_STORE:-s3://my-bucket}" | grep -Fx "$name" || { echo "cluster $name not in state store"; exit 1; } Type guard
cluster, err := clientset.GetCluster(ctx, name)
if err != nil { return err }
if cluster == nil { return fmt.Errorf("cluster %q not found in state store %s", name, stateStore) } Try / catch
out, err := runGetInstances(name)
if err != nil {
if strings.Contains(err.Error(), "cluster not found") {
fmt.Fprintf(os.Stderr, "hint: run `kops get clusters` and check KOPS_STATE_STORE\n")
}
return err
} Prevention
- Always set KOPS_CLUSTER_NAME or pass the fully-qualified cluster DNS name
- Pin KOPS_STATE_STORE in your shell profile per environment
- Run `kops get clusters` first when switching environments or state stores
- Use shell completion (ValidArgsFunction) instead of typing cluster names
When it happens
Trigger: Running `kops get instances <NAME>` (or with --name) where options.ClusterName does not match a cluster in the kops state store; GetCluster returns nil with no error and line 105 raises this error.
Common situations: Typo in the cluster name; wrong KOPS_STATE_STORE (e.g. pointing at an empty/different S3 bucket or different region prefix); cluster was deleted; running without a default cluster set in ~/.kube/config or via KOPS_CLUSTER_NAME; name missing the full DNS suffix (e.g. 'foo' instead of 'foo.example.com').
Related errors
- error querying cluster %q: %v
- no cluster found
- getting cluster: %q: %v
- error creating cluster: %v
- error writing additional objects: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/ad7ca4c23825865f.
Report an issue: GitHub.