Kubernetes 101 : The Nodeport service on a single or multiple hosts

The kubernetes services help us connect containerized applications together, they are also used to connect users to containerized applications.

The nodePort service:

The nodePort service is used to help applications access a service from outside the kubernetes cluster.

The nodePort service opens a port on the host containing the pod within the following range (30000 - 32767).

Below is the Yaml configuration file of our nodePort service:

Below is the Yaml file of the pods attached to the above nodePort service:

To connect the nodePort service to its pods, we use the label "app: nginxon the pod and the label selector "app: nginx" on the service.

We can create both our pod and its nodePort service, using the below command:

To display our nodePort service, we use the below command:

The nodePort service looks for pods that have labels that match its selector and forwards its requests to.

Pods spanning multiple hosts:

If our "nginxpods are hosted on different nodes instead of one - like in the example above -, kubernetes opens the same nodePort port on all the nodes that host our pods:


Leave as a comment: