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 service IP range is 31000-32000. This range contains 1000 ports, which means that you can create 1000 service resources only. If you need more services, or you need to expose specific ports that aren’t in this range for certain applications, then you need to change the range from the default.

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 --servicecluster-ip-range parameter that contains --service-node-port-range=<start-port>-<endport> 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 from 19000 to 22000, make the following updates:

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

  2. Add a line after the --service-cluster-ip-range as follows: --service-node-portrange=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.