kubernetes/kops · error

error building subnets: %v

Error message

error building subnets: %v

What it means

buildElastigroup calls b.buildSubnets(ig), which gathers the subnets for the instance group via b.GatherSubnets and errors if none are found. This wrapper fires when the group cannot be mapped to any subnet, aborting Elastigroup creation.

Source

Thrown at pkg/model/awsmodel/spotinst.go:329

		return fmt.Errorf("error building load balancers: %v", err)
	}

	// User data.
	group.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig)
	if err != nil {
		return fmt.Errorf("error building user data: %v", err)
	}

	// Public IP.
	group.AssociatePublicIPAddress, err = b.buildPublicIPOpts(ig)
	if err != nil {
		return fmt.Errorf("error building public ip options: %v", err)
	}

	// Subnets.
	group.Subnets, err = b.buildSubnets(ig)
	if err != nil {
		return fmt.Errorf("error building subnets: %v", err)
	}

	// Capacity.
	group.MinSize, group.MaxSize = b.buildCapacity(ig)

	// Monitoring.
	group.Monitoring = ig.Spec.DetailedInstanceMonitoring

	// Tags.
	group.Tags, err = b.buildTags(ig)
	if err != nil {
		return fmt.Errorf("error building cloud tags: %v", err)
	}

	// Auto Scaler.
	group.AutoScalerOpts, err = b.buildAutoScalerOpts(b.ClusterName(), ig)
	if err != nil {
		return fmt.Errorf("error building auto scaler options: %v", err)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the inner error: it names the instance group and its spec.subnets.
  2. Set spec.subnets on the instance group to names present in cluster.spec.subnets.
  3. Verify cluster.spec.subnets and topology (public/private) are defined for every zone the IG spans.
  4. Re-run `kops update cluster`.

Example fix

// before
metadata:
  name: nodes
spec: {}
// after
spec:
  subnets:
  - us-east-1a
  - us-east-1b
Defensive patterns

Strategy: validation

Validate before calling

if len(ig.Spec.Subnets) == 0 {
  return fmt.Errorf("instance group %s must define spec.subnets", ig.Name)
}

Try / catch

if err := kopsUpdate(); err != nil {
  if strings.Contains(err.Error(), "error building subnets") {
    // set spec.subnets to valid cluster subnet names and retry
  }
}

Prevention

When it happens

Trigger: `kops update cluster` with Spotinst where GatherSubnets returns an error (IG references unknown subnets / topology mismatch) or returns zero subnets — the inner message is 'could not determine any subnets for SpotInstanceGroup %q'.

Common situations: Instance group created without spec.subnets; subnet names misspelled; cluster migrated from public to private topology leaving stale IG subnet references; Spotinst-hybrid IGs copied from templates of another cluster.

Related errors


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