How to expose a Kubernetes service on a specific Nodeport?

后端 未结 6 2080
不思量自难忘°
不思量自难忘° 2021-02-07 00:04

I have create a pod with the below yaml definition.

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: m         


        
6条回答
  •  暖寄归人
    2021-02-07 00:13

    Your question is about exposing the NodePort type of service on a specific port. For that you need to specify the nodePort field under ports in your service definition.

    kind: Service
    apiVersion: v1
    metadata:
      name: my-service
    spec:
      selector:
        app: myapp
      ports:
      - protocol: TCP
        port: 3000
        nodePort: 32321
      type: NodePort
    

    Note that it has to be within a given range provided in the configs. Which defaults to 30000-32767. This range can be specified in the kube-apiserver configs using the --service-node-port-range option.

提交回复
热议问题