Create a yaml file for the service like below.

  • app = the app label of the pod
  • port = the port the nodes will listen on
  • target = ports the pods are listening on the node port will be forwarded to
  • externalIPs = the IP addresses of the nodes that will listen for the port
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: task-pv-pod
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 80
  externalIPs:
    - 192.168.123.60
    - 192.168.123.61

kubectl apply -f the-name-of-the-yaml-file.yaml