Kubernetes NodePort (Default_range + user_defined_range) on a cluster Or it can be just one range only

1/9/2020

Is it possible to have NodePort Default_range + user_defined_range on a kubernetes cluster Or it can be just one range only

Can we configure to have say default range plus a range of user defined values ? Like default range is 30000-32767 can we have additional range from 40000-41000 as well ?

Will like to retain default range for other applications in cluster but build one range specific to my application.

I have tested assigning port outside the range it clearly fails so the range is hard defined will like to understand if there is any way to have two range or user needs to live with default range or custom range (i.e. two diffrent range in single cluster are not supported )

ubuntu@cluster-master:~$ kubectl expose deployment nginx --type=NodePort --port=80 --dry-run -o yaml

apiVersion: v1

kind: Service

metadata:

  creationTimestamp: null

  labels:

    run: nginx

  name: nginx

spec:

  ports:

  - port: 80

    protocol: TCP

    targetPort: 80

    nodePort: 40000

  selector:

    run: nginx

  type: NodePort

status:

  loadBalancer: {}
ubuntu@cluster-master:~$ kubectl create -f service.yaml

The Service "nginx" is invalid: spec.ports[0].nodePort: Invalid value: 40000: provided port is not in the valid range. The range of valid ports is 30000-32767
-- DT.
kubernetes
service-node-port-range

2 Answers

1/10/2020

With above answer as input and below testing i was able to conclude that this is not a supported function and will have to live with one NodePort range per cluster.

I was able to try following by updating the manifests file for kube-apiserver.

Upon adding flag --service-node-port-range with multiple range values i notice that kube-apiserv is only honoring one flag (last in list) and so i am not able to get it to set two different ranges.

Tried following two syntax on file.

With below syntax last flag in file overrides the value of all preceding flags that is the range becomes 40000 to 41000 only

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    component: kube-apiserver
    tier: control-plane
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
  .
  .
  .
    - --service-node-port-range=30000-32000
    - --service-node-port-range=38000-39000
    - --service-node-port-range=40000-41000
  .
  .
  .

Tested by createing service with sucess on the port range 40000-41000

$ kubectl get service nginx
NAME    TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
nginx   NodePort   10.98.125.217   <none>        80:40000/TCP   75m

Second sysntax tried is as below (but kube-apiserv does not honor such formating on range so fails to start so this is no good)

    - --service-node-port-range=3000-32000,40000-41000
-- DT.
Source: StackOverflow

1/10/2020

Unfortunately, it is not possible that way.

The default range is indeed 30000-32767 but it can be changed by setting the --service-node-port-range Update the file /etc/kubernetes/manifests/kube-apiserver.yaml and add the line --service-node-port-range=xxxxx-yyyyy

Be careful however and not to generate any configuration issues as the range was picked to avoid conflicts with anything else on the host machine network.

I think that the best solution for you would be to set a single but wider range.

I hope it helps.

-- OhHiMark
Source: StackOverflow