Kubernetes NodePort Custom Port

Viewed 22957

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.

5 Answers

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

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

Yeah you can define all those three port by your own

apiVersion: v1
kind: Service
metadata:
  name: posts-srv
spec:
  type: NodePort
  selector:
    app: posts
  ports:
    - name: posts
      protocol: TCP
      port: 4000
      targetPort: 4000
      nodePort: 31515

Related