本文介绍了Kubernetes NodePort自定义端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在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.

因此具有指定NodePortService示例看起来像这样:

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自定义端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 11:54