{"record":{"id":"19db51d932615de4","repo":"kubernetes/kops","slug":"error-parsing-servicenodeportrange-q","errorCode":null,"errorMessage":"error parsing ServiceNodePortRange %q","messagePattern":"error parsing ServiceNodePortRange %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/model/context.go","lineNumber":402,"sourceCode":"func (b *KopsModelContext) IsIPv6Only() bool {\n\treturn b.Cluster.Spec.IsIPv6Only()\n}\n\n// WellKnownServiceIP returns a service ip with the service cidr\nfunc (b *KopsModelContext) WellKnownServiceIP(id int) (net.IP, error) {\n\treturn components.WellKnownServiceIP(&b.Cluster.Spec.Networking, id)\n}\n\n// NodePortRange returns the range of ports allocated to NodePorts\nfunc (b *KopsModelContext) NodePortRange() (utilnet.PortRange, error) {\n\t// defaultServiceNodePortRange is the default port range for NodePort services.\n\tdefaultServiceNodePortRange := utilnet.PortRange{Base: 30000, Size: 2768}\n\n\tkubeApiServer := b.Cluster.Spec.KubeAPIServer\n\tif kubeApiServer != nil && kubeApiServer.ServiceNodePortRange != \"\" {\n\t\terr := defaultServiceNodePortRange.Set(kubeApiServer.ServiceNodePortRange)\n\t\tif err != nil {\n\t\t\treturn utilnet.PortRange{}, fmt.Errorf(\"error parsing ServiceNodePortRange %q\", kubeApiServer.ServiceNodePortRange)\n\t\t}\n\t}\n\n\treturn defaultServiceNodePortRange, nil\n}\n\n// UseServiceAccountExternalPermissions returns true if we are using service-account bound IAM roles.\nfunc (b *KopsModelContext) UseServiceAccountExternalPermissions() bool {\n\treturn b.Cluster.Spec.IAM != nil &&\n\t\tfi.ValueOf(b.Cluster.Spec.IAM.UseServiceAccountExternalPermissions)\n}\n\n// NetworkingIsCalico returns true if we are using calico networking\nfunc (b *KopsModelContext) NetworkingIsCalico() bool {\n\treturn b.Cluster.Spec.Networking.Calico != nil\n}\n\n// NetworkingIsCilium returns true if we are using cilium networking","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/model/context.go#L384-L420","documentation":"buildCertificatePairTask (pkg/model/context.go:402) parses kubeAPIServer.serviceNodePortRange from the cluster spec using utilnet.PortRange.Set. The default is 30000-32767; if the user-provided range string cannot be parsed by k8s.io/apimachinery's PortRange (wrong format, non-numeric, or an invalid base/size combination), this error is returned.","triggerScenarios":"Setting spec.kubeAPIServer.serviceNodePortRange to a string like '30000-32000 ' with stray characters, 'abc', '30000/', or a range whose base+size overflows the valid port space (base+size > 65536, size 0).","commonSituations":"Customizing the NodePort range to narrow it (e.g. '30000-30100') and mistyping the syntax; copying a range from Kubernetes docs written as YAML list instead of the single string form kOps expects.","solutions":["Set serviceNodePortRange to a valid single string of the form 'base-size', e.g. \"30000-32768\" (this field is Base+Size semantics, not lo-hi)","Remove the field entirely to fall back to the default 30000-32767 range","Check for whitespace or stray characters in the YAML value","Re-run 'kops update cluster' and verify the api-server manifest gets the correct --service-node-port-range"],"exampleFix":"// before\nkubeAPIServer:\n  serviceNodePortRange: 30000-32000  # parsed as wrong type/overflows base semantics\n// after\nkubeAPIServer:\n  serviceNodePortRange: \"30000-2001\"  # base=30000, size=2001 => ports 30000-32000","handlingStrategy":"validation","validationCode":"re := regexp.MustCompile(`^(\\d+)-(\\d+)$`)\nm := re.FindStringSubmatch(spec.KubeAPIServer.ServiceNodePortRange)\nif m == nil { return errors.New(\"serviceNodePortRange must look like \\\"30000-2001\\\" (base-size)\") }\nbase, _ := strconv.Atoi(m[1]); size, _ := strconv.Atoi(m[2])\nif base < 0 || size <= 0 || base+size > 65536 { return errors.New(\"port range out of bounds\") }","typeGuard":null,"tryCatchPattern":"pr := utilnet.PortRange{Base: 30000, Size: 2768}\nif err := pr.Set(spec.KubeAPIServer.ServiceNodePortRange); err != nil {\n\t// fall back to default and surface a warning\n\tlog.Warningf(\"invalid ServiceNodePortRange %q: %v; using default\", spec.KubeAPIServer.ServiceNodePortRange, err)\n}","preventionTips":["Remember the field is base-size semantics, not lo-hi","Always quote the YAML value as a string","Keep the range within 1-65535 and size > 0","Omit the field if you want the default 30000-32767"],"tags":["kops","kube-apiserver","port-range","configuration"],"backgroundTag":"invalid-port-range","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}