kubernetes/kops · error

cluster %v does not exist (try adding --force flag)

Error message

cluster %v does not exist (try adding --force flag)

What it means

Raised by `kops replace` when the configuration being replaced refers to a cluster that is not found in the state store and --force was not passed. It is a deliberate guard: without --force the command refuses to implicitly create a new cluster from a replace operation.

Source

Thrown at cmd/kops/replace.go:140

					}
					status, err := cloud.FindClusterStatus(v)
					if err != nil {
						return err
					}

					// Check if the cluster exists already
					clusterName := v.Name
					cluster, err := clientset.GetCluster(ctx, clusterName)
					if err != nil {
						if errors.IsNotFound(err) {
							cluster = nil
						} else {
							return fmt.Errorf("error fetching cluster %q: %v", clusterName, err)
						}
					}
					if cluster == nil {
						if !c.Force {
							return fmt.Errorf("cluster %v does not exist (try adding --force flag)", clusterName)
						}

						err = cloudup.PerformAssignments(v, vfsContext, cloud)
						if err != nil {
							return fmt.Errorf("error populating configuration: %w", err)
						}

						_, err = clientset.CreateCluster(ctx, v)
						if err != nil {
							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)
						}
					}
				}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Add --force to create the cluster if creation is intended
  2. Fix metadata.name in the manifest to match the existing cluster
  3. Verify KOPS_STATE_STORE points at the store containing the cluster (`kops get clusters`)
  4. Create the cluster with `kops create -f` instead of replace if that was the intent

Example fix

// before
kops replace -f cluster.yaml
// after
kops replace -f cluster.yaml --force
Defensive patterns

Strategy: validation

Validate before calling

existing, err := clientset.GetCluster(ctx, clusterName)
clusterExists := err == nil
if !clusterExists && !force {
    return fmt.Errorf("refusing to replace nonexistent cluster %s without --force", clusterName)
}

Try / catch

if err != nil && !strings.Contains(err.Error(), "does not exist") {
    return err
}
// otherwise prompt or append --force deliberately

Prevention

When it happens

Trigger: Replacing a Cluster manifest whose name (v.Name) has no matching cluster in the state store, without the --force flag. Often the cluster name in the manifest is wrong or the state store points elsewhere.

Common situations: Typo in metadata.name of the cluster manifest; KOPS_STATE_STORE pointing at a different store than the one holding the cluster; genuinely wanting to create the cluster via replace but forgetting --force; renamed cluster.

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/7e46113b6a676d18. Report an issue: GitHub.