Extending the default NodePort range

You can increase or change the default range of ports that are used by NodePorts to allow specific ports to be opened for your application needs.

By default, the range of the service NodePorts is 30000-32768. This range contains 2768 ports, which means that you can create up to 2768 services with NodePorts. If you need more services, or you need to expose specific ports that are not in this range for certain applications, then you need to change the default range.

Complete the following steps on each master node in your cluster:

  1. Back up the master.json file.

    cp /etc/cfc/pods/master.json <back_up_location>
    
  2. From the backup location, edit the master.json file by adding a line after the --service-cluster-ip-range parameter that contains --service-node-port-range=<start-port>-<end-port> to suit the needs of your cluster.

  3. Add a comma to the end of the --service-cluster-ip-range line.

  4. For high availability environments, you must update the master.json file on each master node one by one. Kubernetes services aren’t interrupted during the update process.

For example, to change the port range to be 19000 - 22000, make the following updates:

  1. Change --service-cluster-ip-range=10.0.0.0/16 to add a comma: --service-cluster-ip-range=10.0.0.0/16,

  2. Add a line after the --service-cluster-ip-range as follows: --service-node-port-range=19000-22000

  3. Copy over the modified file to update the static pod manifest file:

    cp /<back_up_location>/master.json /etc/cfc/pods/
    

When the manifest file updates, Kubelet restarts all the static pods, which include the kube-apiserver, kube-controller-manager, and kube-scheduler.