kubernetes/kops · error
no subnets found in cluster %q
Error message
no subnets found in cluster %q
What it means
When auto-selecting a subnet for the MachineDeployment, the command collects cluster.Spec.Networking.Subnets into a set; if the set is empty it returns 'no subnets found in cluster %q'. A cluster spec with no subnets cannot host worker machines.
Source
Thrown at pkg/commands/toolbox/clusterapi/generate_machinedeployment.go:123
if err != nil {
return err
}
cluster, err := clientset.GetCluster(ctx, options.ClusterName)
if err != nil {
return err
}
// TODO: Sync with LinkToSubnet and support ID
subnet := options.Subnet
if subnet == "" {
subnets := sets.New[string]()
for _, subnet := range cluster.Spec.Networking.Subnets {
subnets.Insert(subnet.Name)
}
if subnets.Len() == 0 {
return fmt.Errorf("no subnets found in cluster %q", options.ClusterName)
}
if subnets.Len() > 1 {
klog.Warningf("multiple subnets found in cluster %q; using an arbitrary subnet", options.ClusterName)
}
subnet = sets.List(subnets)[0]
log.Info("selected subnet", "subnet", subnet)
}
zones := options.Zones
// TODO: When to use cluster zones, when to use IG zones?
// if zone == "" {
// for _, subnetCandidate := range cluster.Spec.Networking.Subnets {
// if subnetCandidate.Name == subnet {
// zone = subnetCandidate.Zone
// }
// }
// if zone == "" {View on GitHub (pinned to 4c8573c808)
Solutions
- Add subnets to the cluster spec: `kops edit cluster` and define subnets under spec.networking.subnets, then `kops update cluster`.
- Re-run `kops create cluster` with valid --zones so subnets are generated.
- Verify with `kops get cluster -oyaml | grep -A5 subnets` that subnets exist before generating.
Example fix
// before: cluster spec
networking:
subnets: []
// after: kops edit cluster
networking:
subnets:
- name: us-east-1a
type: Public
zone: us-east-1a Defensive patterns
Strategy: validation
Validate before calling
cluster, err := clientset.GetCluster(ctx, options.ClusterName)
if err != nil { return err }
if cluster.Spec.Networking == nil || len(cluster.Spec.Networking.Subnets) == 0 {
return fmt.Errorf("cluster %q has no subnets; run kops edit cluster first", options.ClusterName)
} Type guard
func clusterHasSubnets(c *api.Cluster) bool {
return c != nil && c.Spec.Networking != nil && len(c.Spec.Networking.Subnets) > 0
} Try / catch
if err := RunGenerateMachineDeployment(ctx, f, out, options); err != nil {
if strings.Contains(err.Error(), "no subnets found in cluster") {
return fmt.Errorf("fix cluster spec (add spec.networking.subnets) then retry: %w", err)
}
return err
} Prevention
- Check `kops get cluster -oyaml` for populated subnets before cluster-api generation.
- Never hand-strip subnets from the cluster spec.
- Run `kops update cluster` after creating a cluster so the spec is fully populated.
- Guard automation with a spec-validation preflight step.
When it happens
Trigger: Generating a MachineDeployment for a cluster whose spec has an empty Spec.Networking.Subnets list — e.g. a partially created or hand-edited cluster config, or a spec that failed population.
Common situations: Manually stripped subnets in `kops edit cluster`; clusters created from incomplete templates; spec fetched from a statestore before initial update populated networking.
Related errors
- found multiple subnets with name: %q
- error creating kops config template: %w
- error creating gcp machine template: %w
- error building machine deployments: %w
- configuration must include Subnets
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/4ebe9723cfc757e6.
Report an issue: GitHub.