问题描述
是否可以在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服务器节点端口范围的信息,请参见此.
For more information on NodePort, see this doc. For configuring API Server Node Port range please see this.
这篇关于Kubernetes NodePort自定义端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!