I'm new to Kubernetes. In Kubernetes why NodePort alone has a default port range from 30000 - 32767? Even if we change the default to user-defined port ranges why only 2767 ports are allowed?
Please help me understand. Thanks in advance.
This range was picked to avoid conflicts with anything else on the host machine network since in many cases it is assigned dynamically (manual option is also possible). For example if you'll set it up from range 1-32767 your allocated nodePort
might be in conflict with port 22.
The reasons are pretty much well covered here by @thockin:
- We don't want service node ports to tromp on real ports used by the node
- We don't want service node ports to tromp on pod host ports.
- We don't want to randomly allocate someone port 80 or 443 or 22.
Looking at the code I see that the range is not limited by it. You can find code snippets here, here and in the godocs here.
I've also performed quick test when I set higher default range it works fine for me:
➜ temp kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-service NodePort 10.100.214.233 <none> 80:14051/TCP 68s
my-service2 NodePort 10.97.67.57 <none> 80:10345/TCP 6s