Kubernetes NodePort Custom Port

限于喜欢 提交于 2019-11-27 02:32:16

问题


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.


回答1:


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.

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

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




回答2:


You can define static NodePort using nodeport in service.yaml file

spec:
  type: NodePort
  ports:
    - port: 3000
      nodePort: 31001
      name: http



来源:https://stackoverflow.com/questions/43935502/kubernetes-nodeport-custom-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!