kubernetes/kops · error
cluster %q already exists
Error message
cluster %q already exists
What it means
After populating config, RunCreate calls clientset.CreateCluster to persist the cluster. When the registry reports the cluster already exists (apierrors.IsAlreadyExists), the CLI returns "cluster %q already exists" instead of the generic create error.
Source
Thrown at cmd/kops/create.go:148
}
switch v := o.(type) {
case *kopsapi.Cluster:
cloud, err := cloudup.BuildCloud(v)
if err != nil {
return err
}
// Adding a PerformAssignments() call here as the user might be trying to use
// the new `-f` feature, with an old cluster definition.
err = cloudup.PerformAssignments(v, vfsContext, cloud)
if err != nil {
return fmt.Errorf("error populating configuration: %v", err)
}
_, err = clientset.CreateCluster(ctx, v)
if err != nil {
if apierrors.IsAlreadyExists(err) {
return fmt.Errorf("cluster %q already exists", v.ObjectMeta.Name)
}
return fmt.Errorf("error creating cluster: %v", err)
}
fmt.Fprintf(&sb, "Created cluster/%s\n", v.ObjectMeta.Name)
clusters = append(clusters, v)
// cSpec = true
case *kopsapi.InstanceGroup:
clusterName = v.ObjectMeta.Labels[kopsapi.LabelClusterName]
if clusterName == "" {
return fmt.Errorf("must specify %q label with cluster name to create instanceGroup", kopsapi.LabelClusterName)
}
cluster, err := clientset.GetCluster(ctx, clusterName)
if err != nil {
return fmt.Errorf("error querying cluster %q: %v", clusterName, err)
}
if cluster == nil {View on GitHub (pinned to 4c8573c808)
Solutions
- Use `kops replace -f cluster.yaml` to update the existing cluster spec instead of create
- Delete the existing cluster with `kops delete cluster --name <name> --yes` if it should be recreated
- Choose a different cluster name if this is a new cluster
- Verify state store (KOPS_STATE_STORE) points where you expect
Example fix
// before kops create -f cluster.yaml // after kops replace -f cluster.yaml
Defensive patterns
Strategy: validation
Validate before calling
// check existence before create
existing, err := clientset.ListClusters(ctx, nil)
if err == nil {
for _, c := range existing.Items {
if c.Name == cluster.Name {
return fmt.Errorf("cluster %s exists; use kops replace", c.Name)
}
}
} Try / catch
_, err := clientset.CreateCluster(ctx, v)
if err != nil {
if apierrors.IsAlreadyExists(err) {
return fmt.Errorf("cluster %q already exists", v.ObjectMeta.Name)
}
return fmt.Errorf("error creating cluster: %v", err)
} Prevention
- Use `kops replace -f` for updates, create only for new clusters
- Ensure unique cluster names across manifests
- Confirm KOPS_STATE_STORE points to the intended store before create
- Script idempotently: check-then-create or use replace
When it happens
Trigger: `kops create -f cluster.yaml` with a cluster whose metadata.name matches a Cluster already registered in the kOps state store.
Common situations: Re-running create for an existing cluster (instead of `kops replace -f` or `kops update`); multiple manifests defining the same cluster name; stale state store pointing at a previously created cluster.
Related errors
- error creating cluster: %v
- Error too many '=' (%d) in %s
- at least one channel URL is required
- building menu for %q: %w
- applying %q: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/4d59b0523fb9cae2.
Report an issue: GitHub.