kubernetes/kops · error
cluster %q not found
Error message
cluster %q not found
What it means
GetCluster in kops can return a nil cluster with a nil error (the clientset convention for 'not found'). This error is raised to convert that silent nil result into an explicit 'cluster not found' message. It means the state store has no cluster object with the given name.
Source
Thrown at cmd/kops/root.go:353
return c.clusterName
}
func GetCluster(ctx context.Context, factory commandutils.Factory, clusterName string) (*kopsapi.Cluster, error) {
if clusterName == "" {
return nil, field.Required(field.NewPath("clusterName"), "Cluster name is required")
}
clientset, err := factory.KopsClient()
if err != nil {
return nil, err
}
cluster, err := clientset.GetCluster(ctx, clusterName)
if err != nil {
return nil, fmt.Errorf("error reading cluster configuration: %v", err)
}
if cluster == nil {
return nil, fmt.Errorf("cluster %q not found", clusterName)
}
if clusterName != cluster.ObjectMeta.Name {
return nil, fmt.Errorf("cluster name did not match expected name: %v vs %v", clusterName, cluster.ObjectMeta.Name)
}
return cluster, nil
}
func GetClusterNameForCompletionNoKubeconfig(clusterArgs []string) (clusterName string, completions []string, directive cobra.ShellCompDirective) {
if len(clusterArgs) > 0 {
return clusterArgs[0], nil, 0
}
if rootCommand.clusterName != "" {
return rootCommand.clusterName, nil, 0
}
return "", []string{"--name"}, cobra.ShellCompDirectiveNoFileCompView on GitHub (pinned to 4c8573c808)
Solutions
- List clusters with kops get clusters and copy the exact cluster name.
- Use the fully-qualified cluster DNS name (e.g. name.k8s.local for gossip clusters).
- Confirm KOPS_STATE_STORE / --state points at the store containing the cluster.
- Create the cluster first (kops create cluster ...) if it does not exist yet.
Example fix
// before kops create ig nodes --name mycluster // after kops get clusters # shows: mycluster.k8s.local kops create ig nodes --name mycluster.k8s.local
Defensive patterns
Strategy: validation
Validate before calling
EXISTING=$(kops get clusters -o name | grep -F "$CLUSTER_NAME") || { echo "cluster $CLUSTER_NAME does not exist"; exit 1; } Try / catch
cluster, err := GetCluster(ctx, clusterName)
if err != nil {
return err
}
if cluster == nil {
return fmt.Errorf("cluster %q not found in state store; run 'kops get clusters' to list valid names", clusterName)
} Prevention
- Copy cluster names verbatim from kops get clusters output
- Remember gossip clusters require the .k8s.local suffix
- Pin KOPS_STATE_STORE per environment (dev/staging/prod)
- Validate names in CI before running mutating commands
When it happens
Trigger: clientset.GetCluster returns (nil, nil) — i.e. no cluster configuration exists at the requested name in the state store — while running commands like create instancegroup, create keypair, create secret, or create sshpublickey.
Common situations: Typo in the cluster name or case mismatch; KOPS_STATE_STORE pointing to a different bucket than the one the cluster lives in; DNS/name mismatch such as using a short name instead of the fully-qualified cluster name (e.g. 'mycluster' vs 'mycluster.k8s.local').
Related errors
- error loading NodeupConfig %q: %v
- error querying cluster %q: %v
- error getting cluster: %q: %v
- listing keysets: %v
- adding encryptionconfig secret: %v
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/609a4fec85c65599.
Report an issue: GitHub.