Kubernetes NodePort Custom Port

Is there a way to specify a custom NodePort port in the definition of yaml kubernetes services? I need to be able to explicitly define the port in my configuration file.

+24
source share
2 answers

You can set the type NodePortin your deployment Service. Please note that for your server the API is configured Node Port Rangewith the parameter --service-node-port-range(default 30000-32767). You can also specify a port in this range by specially setting the attribute NodePortbelow the object Port, or the system will select a port in this range for you.

So, an example Servicewith the above NodePortwill 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 about NodePort, see this document . To configure the Node API Server Port Range, see this .

+33
source

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

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

+1
source

Source: https://habr.com/ru/post/1676995/


All Articles