问题描述
有没有办法在 kubernetes 服务 YAML 定义中指定自定义 NodePort 端口?我需要能够在我的配置文件中明确定义端口.
Is there way to specify a custom NodePort port in a kubernetes service YAML definition?I need to be able to define the port explicitly in my configuration file.
推荐答案
您可以在您的 Service
部署中设置类型 NodePort
.请注意,为您的 API 服务器配置了一个 Node Port Range
选项 --service-node-port-range
(默认情况下 30000-32767
代码>).您也可以通过设置Port
对象下的nodePort
属性来具体指定该范围内的端口,否则系统会为您选择该范围内的端口.
You can set the type NodePort
in your Service
Deployment. Note that there is a Node Port Range
configured for your API server with the option --service-node-port-range
(by default 30000-32767
). You can also specify a port in that range specifically by setting the nodePort
attribute under the Port
object, or the system will chose a port in that range for you.
因此,具有指定 NodePort
的 Service
示例将如下所示:
So a Service
example with specified NodePort
would look like this:
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
name: nginx
spec:
type: NodePort
ports:
- port: 80
nodePort: 30080
name: http
- port: 443
nodePort: 30443
name: https
selector:
name: nginx
有关 NodePort 的更多信息,请参阅此文档.有关配置 API 服务器节点端口范围,请参阅this.
For more information on NodePort, see this doc. For configuring API Server Node Port range please see this.
这篇关于Kubernetes NodePort 自定义端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!