在Kubernetes中,为什么NodePort的默认端口范围为30000-32767? [英] In Kubernetes why NodePort has default port range from 30000 - 32767?

查看:584
本文介绍了在Kubernetes中,为什么NodePort的默认端口范围为30000-32767?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Kubernetes的新手.在Kubernetes中,为什么仅NodePort会具有默认端口范围 30000-32767 ?即使我们将默认端口更改为用户定义的端口范围,为什么也只允许 2767 端口?

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.

推荐答案

选择此范围是为了避免与主机网络上的任何其他内容发生冲突,因为在许多情况下,该范围是动态分配的(也可以使用手动选项).例如,如果您将其设置为范围1-32767,则您分配的nodePort可能与端口22冲突.

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.

此处由@thockin很好地涵盖了原因:

The reasons are pretty much well covered here by @thockin:

  1. 我们不希望服务节点端口在该节点使用的实际端口上占满
  2. 我们不希望服务节点端口在Pod主机端口上奔跑.
  3. 我们不想为某人随机分配端口80或443或22.

看代码,我发现范围不受它的限制.您可以在此处此处并在godocs 此处.

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

这篇关于在Kubernetes中,为什么NodePort的默认端口范围为30000-32767?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆