kubernetes/kops · error

cluster %q not found

Error message

cluster %q not found

What it means

With the cluster name resolved from the label, kops calls clientset.GetCluster. If the cluster is not found in the state store, the NotFound error is converted to this explicit 'cluster %q not found' message rather than creating the group.

Source

Thrown at cmd/kops/replace.go:168

							return fmt.Errorf("error creating cluster: %v", err)
						}
					} else {
						_, err = clientset.UpdateCluster(ctx, v, status)
						if err != nil {
							return fmt.Errorf("error replacing cluster: %v", err)
						}
					}
				}

			case *kopsapi.InstanceGroup:
				clusterName := v.ObjectMeta.Labels[kopsapi.LabelClusterName]
				if clusterName == "" {
					return fmt.Errorf("must specify %q label with cluster name to replace instanceGroup", kopsapi.LabelClusterName)
				}
				cluster, err := clientset.GetCluster(ctx, clusterName)
				if err != nil {
					if errors.IsNotFound(err) {
						return fmt.Errorf("cluster %q not found", clusterName)
					}
					return fmt.Errorf("error fetching cluster %q: %v", clusterName, err)
				}
				// check if the instancegroup exists already
				igName := v.ObjectMeta.Name
				ig, err := clientset.InstanceGroupsFor(cluster).Get(ctx, igName, metav1.GetOptions{})
				if err != nil {
					if errors.IsNotFound(err) {
						if !c.Force {
							return fmt.Errorf("instanceGroup: %v does not exist (try adding --force flag)", igName)
						}
					} else {
						return fmt.Errorf("unable to check for instanceGroup: %v", err)
					}
				}
				switch ig {
				case nil:
					klog.Infof("instanceGroup: %v was not found, creating resource now", igName)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Verify the label value matches an existing cluster: `kops get clusters`
  2. Correct KOPS_STATE_STORE if it points at the wrong store
  3. Update the kops.k8s.io/cluster label to the actual target cluster name
  4. Create the cluster first before replacing its instance groups

Example fix

// before
labels:
  kops.k8s.io/cluster: old.example.com
// after
labels:
  kops.k8s.io/cluster: new.example.com
Defensive patterns

Strategy: validation

Validate before calling

clusterName := ig.ObjectMeta.Labels[kopsapi.LabelClusterName]
if _, err := clientset.GetCluster(ctx, clusterName); errors.IsNotFound(err) {
    return fmt.Errorf("cluster %q does not exist in state store; create it first", clusterName)
}

Try / catch

if err != nil {
    if errors.IsNotFound(err) {
        // wrong label value or wrong KOPS_STATE_STORE: surface both possibilities
        return fmt.Errorf("cluster %q not found; check label and KOPS_STATE_STORE", clusterName)
    }
    return err
}

Prevention

When it happens

Trigger: Replacing an InstanceGroup whose kops.k8s.io/cluster label names a cluster that does not exist in the current state store - typical when reusing manifests across state stores or after a cluster rename/deletion.

Common situations: Manifest copied from another cluster; KOPS_STATE_STORE pointing at the wrong bucket; cluster deleted but instancegroup manifests retained; label contains a stale cluster DNS name.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/231338a5c10f24f3. Report an issue: GitHub.