kubernetes/kops · error

instanceGroup %q already exists

Error message

instanceGroup %q already exists

What it means

When creating an InstanceGroup via InstanceGroupsFor(cluster).Create, the backend returns an API IsAlreadyExists error if an instance group with the same name already exists for that cluster; RunCreate wraps it into this friendly message.

Source

Thrown at cmd/kops/create.go:173

			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 {
					return fmt.Errorf("cluster %q not found", clusterName)
				}

				_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, v, metav1.CreateOptions{})
				if err != nil {
					if apierrors.IsAlreadyExists(err) {
						return fmt.Errorf("instanceGroup %q already exists", v.ObjectMeta.Name)
					}
					return fmt.Errorf("error creating instanceGroup: %v", err)
				}
				fmt.Fprintf(&sb, "Created instancegroup/%s\n", v.ObjectMeta.Name)

			case *kopsapi.SSHCredential:
				clusterName = v.ObjectMeta.Labels[kopsapi.LabelClusterName]
				if clusterName == "" {
					return fmt.Errorf("must specify %q label with cluster name to create SSHCredential", kopsapi.LabelClusterName)
				}
				if v.Spec.PublicKey == "" {
					return fmt.Errorf("spec.PublicKey is required")
				}

				cluster, err := clientset.GetCluster(ctx, clusterName)
				if err != nil {
					return err
				}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Use `kops replace -f ig.yaml` to overwrite the existing group
  2. Use `kops apply` / update the existing group via `kops edit ig <name>` instead of create
  3. Rename the new instance group (unique metadata.name) if it is intended to be an additional group
  4. If unintended duplicate, delete one copy before creating

Example fix

// before
kops create -f nodes.yaml
// after
kops replace -f nodes.yaml
Defensive patterns

Strategy: try-catch

Validate before calling

existing, _ := clientset.InstanceGroupsFor(cluster).Get(ctx, ig.Name, metav1.GetOptions{})
if existing != nil {
    // use replace instead of create
}

Try / catch

if err != nil && strings.Contains(err.Error(), "already exists") {
    _, err = clientset.InstanceGroupsFor(cluster).Update(ctx, ig, metav1.UpdateOptions{})
}

Prevention

When it happens

Trigger: `kops create -f ig.yaml` (or a file containing an InstanceGroup) where an InstanceGroup with the same metadata.name already exists in the target cluster — including a duplicate IG document inside the same multi-section -f file.

Common situations: Re-running a create script that already succeeded partially; copying a nodes instance group file without renaming it; applying the same manifest twice instead of using `kops replace` or `kops apply`.

Related errors


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