Home > database >  What happens if a port in Kubernetes NodePort range is already in use by another process on host mac
What happens if a port in Kubernetes NodePort range is already in use by another process on host mac

Time:10-15

When a Kubernetes attempts to allocate a random port in NodePort range (30000-32767) and it happens to be in use by another process running on the host, will Kubernetes simply use another random port in NodePort range? Or will it throw an error?

I know that host processes should not be configured to use ports in NodePort range but this question is not about best practices. I just want to know how Kubernetes will respond in such a situation.

CodePudding user response:

This is the main reason why Kubernetes choose port range 30000-32767 as its default node port range and this range avoids conflicts with any process runs on the common port on the host machine (for example, 22, 80, 443 etc).

Please follow this link . All these are explained very well by one of the Kubernetes official Members.

And the answer to your question

Kubernetes just takes a random port and if that one conflicts and it finds that it isn't free it takes the next one. You can refer to this Kubernetes golang code. (It is actually a set of test cases for the node port allocation operation. You can understand the behaviour from there).

And just a piece of additional information, it's possible to modify the node port default range by giving --service-node-port-range argument to the kube-apiserver

  • Related