kubernetes/kops · error
must specify %q label with cluster name to create instanceGr
Error message
must specify %q label with cluster name to create instanceGroup
What it means
`kops create -f` decodes each YAML section and dispatches by Go type. When it encounters a kops InstanceGroup object, it requires the metadata.labels entry keyed by kopsapi.LabelClusterName ("kops.k8s.io/cluster") to know which cluster the instance group belongs to; without it the command cannot resolve the parent cluster and fails fast.
Source
Thrown at cmd/kops/create.go:159
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 {
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)View on GitHub (pinned to 4c8573c808)
Solutions
- Add `kops.k8s.io/cluster: <cluster-name>` under metadata.labels of the InstanceGroup document
- Create the instance group via `kops create ig --name <cluster> ...` or `kops create -f` after fixing the manifest
- Verify the label key is exactly kops.k8s.io/cluster (not clusterName or kops/cluster)
Example fix
# before
metadata:
name: nodes
spec: {}
# after
metadata:
name: nodes
labels:
kops.k8s.io/cluster: mycluster.example.com
spec: {} Defensive patterns
Strategy: validation
Validate before calling
ig, _ := decodeSection(yaml)
if v, ok := ig.(*kopsapi.InstanceGroup); ok && v.ObjectMeta.Labels[kopsapi.LabelClusterName] == "" {
return fmt.Errorf("IG %s missing label %s", v.Name, kopsapi.LabelClusterName)
} Type guard
func needsClusterLabel(o runtime.Object) (*kopsapi.InstanceGroup, bool) {
ig, ok := o.(*kopsapi.InstanceGroup)
return ig, ok && ig.ObjectMeta.Labels[kopsapi.LabelClusterName] != ""
} Prevention
- Always template metadata.labels with the cluster name when generating IG manifests
- Use `kops create ig` which sets the label for you
- Lint manifests for the kops.k8s.io/cluster label before running create
When it happens
Trigger: Running `kops create -f ig.yaml` where ig.yaml contains a kind: InstanceGroup document whose metadata is missing the label `kops.k8s.io/cluster: <clustername>` (or misspells the label key).
Common situations: Hand-written instance group manifests copied from old blog posts predating the label requirement; templates where labels were stripped; generating IGs with tooling that omits ObjectMeta labels.
Related errors
- cluster %q not found
- instanceGroup %q already exists
- error creating instanceGroup: %v
- must specify %q label with cluster name to create SSHCredent
- instanceGroup: %v does not exist (try adding --force flag)
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/f4da32a2a79417ff.
Report an issue: GitHub.