kubernetes/kops · error

subnet %q must specify a zone or the ID of an existing subne

Error message

subnet %q must specify a zone or the ID of an existing subnet

What it means

FindRegion derives the cluster region from the subnets' zones; each subnet must either declare a zone or reference an existing subnet by ID (from which the zone is later looked up in the cloud). This error is thrown when a subnet has neither a zone nor an ID, so no region can be inferred from it. It enforces that every subnet entry in the cluster spec is usable for region discovery.

Source

Thrown at upup/pkg/fi/cloudup/awsup/aws_utils.go:99

	}

	if os.Getenv("SKIP_REGION_CHECK") != "" {
		klog.Infof("AWS region does not appear to be valid, but skipping because SKIP_REGION_CHECK is set")
		return nil
	}

	return fmt.Errorf("Region is not a recognized EC2 region: %q (check you have specified valid zones?)", region)
}

// FindRegion determines the region from the zones specified in the cluster
func FindRegion(cluster *kops.Cluster) (string, error) {
	region := ""

	for _, subnet := range cluster.Spec.Networking.Subnets {
		if subnet.Zone == "" {
			// The zone of a subnet specified by ID is looked up from the cloud later.
			if subnet.ID == "" {
				return "", fmt.Errorf("subnet %q must specify a zone or the ID of an existing subnet", subnet.Name)
			}
			continue
		}

		if len(subnet.Zone) <= 2 {
			return "", fmt.Errorf("invalid AWS zone: %q in subnet %q", subnet.Zone, subnet.Name)
		}

		zoneRegion := subnet.Zone[:len(subnet.Zone)-1]
		if region != "" && zoneRegion != region {
			return "", fmt.Errorf("error Clusters cannot span multiple regions (found zone %q, but region is %q)", subnet.Zone, region)
		}

		region = zoneRegion
	}

	if region == "" {
		return "", fmt.Errorf("could not determine cluster region: no subnet specifies a zone")

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Set either the zone (e.g. us-east-1a) or the ID of an existing subnet (subnet-xxxxxxxx) on every subnet in cluster.Spec.Networking.Subnets
  2. Run `kops edit cluster` to fix the subnet entries
  3. Validate the spec with `kops validate` / dry-run before re-running create/update

Example fix

// before
subnets:
- name: us-east-1a
// after
subnets:
- name: us-east-1a
  zone: us-east-1a
Defensive patterns

Strategy: validation

Validate before calling

// check every subnet has zone or id before kops create
for _, s := range cluster.Spec.Networking.Subnets {
    if s.Zone == "" && s.ID == "" {
        return fmt.Errorf("subnet %q needs a zone or id", s.Name)
    }
}

Prevention

When it happens

Trigger: Iterating cluster.Spec.Networking.Subnets in FindRegion and encountering a subnet where Zone == "" and ID == "" — the subnet only has a Name field filled in.

Common situations: Hand-edited kops cluster specs where someone added a subnet with just a name; templating tools emitting empty zone fields; subnets defined for other clouds (e.g. GCE/Azure style) copied into an AWS cluster spec.

Related errors


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