kubernetes/kops · error

error node usage class not supported

Error message

error node usage class not supported

What it means

Returned by decorateWithMixedInstancesPolicy in `kops toolbox instance-selector` when the requested EC2 usage class is neither "spot" nor "on-demand". The switch only handles ec2types.UsageClassTypeSpot and ec2types.UsageClassTypeOnDemand; any other value (including an empty/unset value) falls into the default branch. The AWS SDK enum was parsed from the --node-usage-class style flag, so an invalid or misspelled value surfaces here.

Source

Thrown at cmd/kops/toolbox_instance-selector.go:539

	ig.Spec.MachineType = instanceSelections[0]

	switch usageClass {
	case ec2types.UsageClassTypeSpot:
		ondemandBase := int64(0)
		ondemandAboveBase := int64(0)
		spotAllocationStrategy := "capacity-optimized"
		ig.Spec.MixedInstancesPolicy = &kops.MixedInstancesPolicySpec{
			Instances:              instanceSelections,
			OnDemandBase:           &ondemandBase,
			OnDemandAboveBase:      &ondemandAboveBase,
			SpotAllocationStrategy: &spotAllocationStrategy,
		}
	case ec2types.UsageClassTypeOnDemand:
		ig.Spec.MixedInstancesPolicy = &kops.MixedInstancesPolicySpec{
			Instances: instanceSelections,
		}
	default:
		return nil, fmt.Errorf("error node usage class not supported")
	}

	return ig, nil
}

// decorateWithClusterAutoscalerLabels adds cluster-autoscaler discovery tags to the cloudlabels slice
func decorateWithClusterAutoscalerLabels(instanceGroup *kops.InstanceGroup, clusterName string) *kops.InstanceGroup {
	ig := instanceGroup
	if ig.Spec.CloudLabels == nil {
		ig.Spec.CloudLabels = make(map[string]string)
	}
	ig.Spec.CloudLabels["k8s.io/cluster-autoscaler/enabled"] = "1"
	ig.Spec.CloudLabels["k8s.io/cluster-autoscaler/"+clusterName] = "1"
	return ig
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Use `spot` for a spot mixed instances policy: --node-usage-class spot
  2. Use `on-demand` (or `on-demand` exactly as accepted by the ec2types enum) for on-demand instances
  3. Remove the flag to use the tool's default usage class if unsure
  4. Check `kops toolbox instance-selector --help` for the exact accepted values and spelling

Example fix

// before
kops toolbox instance-selector --name nodes --node-usage-class reserved

// after
kops toolbox instance-selector --name nodes --node-usage-class spot
Defensive patterns

Strategy: validation

Validate before calling

switch strings.ToLower(usageClassFlag) {
case "spot", "on-demand", "":
    // ok
default:
    return fmt.Errorf("unsupported usage class %q: use spot or on-demand", usageClassFlag)
}

Prevention

When it happens

Trigger: Passing an unsupported value for the usage-class flag on `kops toolbox instance-selector`, e.g. "reserved", "scheduled", "dedicated", an empty string, or a typo like "on demand" that fails to map to ec2types.UsageClassTypeOnDemand.

Common situations: Confusing EC2 purchasing options (reserved/dedicated hosts) with the spot/on-demand usage class supported by mixed instances policies; typos or capitalization issues in the flag; scripts carrying an invalid default value from a template.

Related errors


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