In Kubernetes why NodePort has default port range from 30000 - 32767?
Asked Answered
H

1

11

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.

Hager answered 2/9, 2020 at 3:12 Comment(1)
You can find some information from hereSuperb
R
12

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:

  1. We don't want service node ports to tromp on real ports used by the node
  2. We don't want service node ports to tromp on pod host ports.
  3. 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
Rolfrolfe answered 2/9, 2020 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.