kubernetes/kops · error

no instance groups found in cluster %q

Error message

no instance groups found in cluster %q

What it means

RunGenerateMachineDeployment lists the cluster's instance groups to infer zones/types; if the list returns zero items it returns 'no instance groups found in cluster %q'. A cluster without instance groups has nothing to derive worker configuration from.

Source

Thrown at pkg/commands/toolbox/clusterapi/generate_machinedeployment.go:156

	// 			zone = subnetCandidate.Zone
	// 		}
	// 	}
	// 	if zone == "" {
	// 		return fmt.Errorf("unable to determine zone for subnet %q in cluster %q; please specify --zone", subnet, options.ClusterName)
	// 	}
	// 	log.Info("selected zone", "zone", zone)
	// }

	instanceType := options.InstanceType
	image := options.Image
	if len(zones) == 0 || instanceType == "" || image == "" {
		instanceGroups, err := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})
		if err != nil {
			return err
		}

		if len(instanceGroups.Items) == 0 {
			return fmt.Errorf("no instance groups found in cluster %q", options.ClusterName)
		}

		if len(zones) == 0 {
			allZones := sets.New[string]()
			for _, ig := range instanceGroups.Items {
				for _, z := range ig.Spec.Zones {
					allZones.Insert(z)
				}
			}
			if allZones.Len() == 0 {
				return fmt.Errorf("no zones found in instance groups in cluster %q", options.ClusterName)
			}

			zones = sets.List(allZones)
			log.Info("selected zones", "zones", zones)
		}

		if instanceType == "" {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Confirm the cluster name and KOPS_STATE_STORE point at the intended cluster (`kops get clusters`).
  2. Run `kops update cluster --yes` first so instance groups are created.
  3. Create instance groups with `kops create instancegroup` or from a template before generating the MachineDeployment.

Example fix

// before: run generation on empty cluster
kops toolbox clusterapi generate machinedeployment --cluster c1.k8s.local --name workers // error
// after: create IG first
kops create instancegroup --cluster c1.k8s.local nodes -o yaml
kops update cluster --name c1.k8s.local --yes
kops toolbox clusterapi generate machinedeployment --cluster c1.k8s.local --name workers
Defensive patterns

Strategy: validation

Validate before calling

igs, err := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})
if err != nil { return err }
if len(igs.Items) == 0 {
	return fmt.Errorf("cluster %q has no instance groups; run kops update cluster first", cluster.Name)
}

Type guard

func hasInstanceGroups(igs *api.InstanceGroupList) bool { return igs != nil && len(igs.Items) > 0 }

Try / catch

if err := RunGenerateMachineDeployment(ctx, f, out, options); err != nil {
	if strings.Contains(err.Error(), "no instance groups found in cluster") {
		return fmt.Errorf("create instance groups (kops create instancegroup / update cluster) before generating: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Running generate machinedeployment against a cluster registered in the API/statestore that has no InstanceGroup objects yet (fresh cluster before `kops update cluster` created IGs, or wrong cluster name/statestore).

Common situations: Pointing at a cluster in a different KOPS_STATE_STORE; running before initial update/apply; instance groups deleted manually.

Related errors


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