kubernetes/kops · error
instanceGroup: %v does not exist (try adding --force flag)
Error message
instanceGroup: %v does not exist (try adding --force flag)
What it means
`kops replace` refuses to replace an InstanceGroup whose name is not found in the state store. Because `replace` is semantically an update operation, kOps conservatively fails instead of silently creating a brand-new InstanceGroup; passing `--force` explicitly opts in to create-on-missing behavior. The check is done via clientset.InstanceGroupsFor(cluster).Get, and the error is returned when errors.IsNotFound(err) is true and c.Force is false.
Source
Thrown at cmd/kops/replace.go:178
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)
_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, v, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("error creating instanceGroup: %v", err)
}
default:
_, err = clientset.InstanceGroupsFor(cluster).Update(ctx, v, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("error replacing instanceGroup: %v", err)
}
}View on GitHub (pinned to 4c8573c808)
Solutions
- Re-run the command with the --force flag: `kops replace -f ig.yaml --force` to create the missing InstanceGroup.
- Verify the `metadata.name` in the manifest matches an existing InstanceGroup (`kops get instancegroups <cluster>`) and fix the typo if not.
- If the IG should already exist, confirm you are pointing at the right cluster/state store (--name and KOPS_STATE_STORE) before forcing creation.
- Alternatively use `kops create -f ig.yaml` when the intent is creation, then `kops update cluster --yes` to apply.
Example fix
# before kops replace -f instancegroup-nodes.yaml // error: instanceGroup: nodes does not exist (try adding --force flag) # after kops replace -f instancegroup-nodes.yaml --force
Defensive patterns
Strategy: validation
Validate before calling
// Before replace, confirm the InstanceGroup exists
name := igManifest.ObjectMeta.Name
_, err := clientset.InstanceGroupsFor(cluster).Get(ctx, name, metav1.GetOptions{})
if errors.IsNotFound(err) {
// either add --force or create first: kops create -f ig.yaml
fmt.Printf("InstanceGroup %s does not exist; use --force or create it\n", name)
} Prevention
- Keep InstanceGroup manifest names in sync with `kops get instancegroups` output before replace
- Use --force deliberately and only when creation is intended
- Pin cluster name with --name to avoid checking the wrong state store
- Script the existence check into CI before running replace
When it happens
Trigger: Running `kops replace -f ig.yaml` where the InstanceGroup name in the manifest (v.ObjectMeta.Name) does not exist in the cluster's state store and the --force flag was not supplied. The Get call returns a NotFound error, triggering this message.
Common situations: Typo in the InstanceGroup name in the manifest; renaming an existing InstanceGroup instead of editing it; replacing a manifest from a different/older cluster whose IGs were deleted; forgetting that replace does not create resources without --force.
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
- cluster %q not found
- must specify %q label with cluster name to create instanceGr
- instanceGroup %q already exists
- error creating instanceGroup: %v
- InstanceGroup %q not found
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/7031dab61c52df5b.
Report an issue: GitHub.