Discovering Kubernetes Services - (NodePort)

Learn about NodePort service in Kubernetes.


NodePort facilitates the routing of external traffic to pods within a Kubernetes cluster. It opens a designated port on each node, through which incoming traffic is directed to the desired service.

Exemple of NodePort service :

apiVersion: v1
kind: Service
metadata:
  name: hello-k8s-service
spec:
  type: NodePort # map *nodePort* on every cluster node
  selector:
    app: helloworld
  ports:
  - port: 8080 # internal cluster port 
    targetPort: 80 # Port app listens on in Pods/containers
    nodePort: 31111 # External port on every cluster node. If you don’t specify this port, it will pick a random port
  

🚨 Good to know

NodePort

  • only have one service per port
  • only use ports 30000–32767