本文介绍了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 服务器节点端口范围,请参阅this.

For more information on NodePort, see this doc. For configuring API Server Node Port range please see this.

这篇关于Kubernetes NodePort 自定义端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-19 11:55