kubernetes/kops · error

Count must be positive or 0

Error message

Count must be positive or 0

What it means

CheckChanges validates the desired Instance task during the apply diff phase. It throws this error when the declared instance group count is negative, since a group must have zero or more instances. kOps cannot compute a valid create/resize delta from a negative Count.

Source

Thrown at upup/pkg/fi/cloudup/linodetasks/instance.go:172

		}
		if changes.Subnet != nil {
			return fi.CannotChangeField("Subnet")
		}
		if changes.RequirePublicInterface != nil {
			return fi.CannotChangeField("RequirePublicInterface")
		}
	} else {
		if expected.Name == nil {
			return fi.RequiredField("Name")
		}
		if expected.Region == "" {
			return fi.RequiredField("Region")
		}
		if expected.Type == "" {
			return fi.RequiredField("Type")
		}
		if expected.Count < 0 {
			return fmt.Errorf("Count must be positive or 0")
		}
		if expected.Subnet == nil {
			return fi.RequiredField("Subnet")
		}
		if expected.RequirePublicInterface == nil {
			return fi.RequiredField("RequirePublicInterface")
		}
		if expected.Image == "" {
			return fi.RequiredField("Image")
		}
		if expected.UserData == nil {
			return fi.RequiredField("UserData")
		}
		if len(expected.AuthorizedKeys) < 1 {
			return fi.RequiredField("AuthorizedKeys")
		}
		if len(expected.Tags) == 0 {
			return fi.RequiredField("Tags")

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Fix the Count field in the Instance task spec to be >= 0
  2. Inspect whatever computed Count (templates, scripts) and clamp to 0 or above
  3. Re-run kops update with the corrected spec

Example fix

// before
Count: -2
// after
Count: 2
Defensive patterns

Strategy: validation

Validate before calling

if instanceTask.Count < 0 { return fmt.Errorf("instance group %q: Count must be >= 0, got %d", name, instanceTask.Count) }

Prevention

When it happens

Trigger: An Instance task in the cluster spec has Count set to a negative integer (e.g. Count: -1), so expected.Count < 0 during CheckChanges.

Common situations: Template or variable interpolation producing a negative count (e.g. autoscaler math like desired - current going below zero), a hand-edited cluster.yaml with a typo, or a script computing replicas wrongly.

Related errors


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