Monday 13 May 2024

Introduction to Kubernetes Services

This article extends my notes from an Udemy course "Kubernetes for the Absolute Beginners - Hands-on". All course content rights belong to course creators. 

The previous article in the series was Introduction to Kubernetes Networking | My Public Notepad

Kubernetes services:
  • Enable communication between various components within and outside of the application
  • Help connecting applications together with other applications or users
For example, our application has groups of pods running various sections, such as a group for serving a front end load to users and other group for running back end processes, and a third group connecting to an external data source. It is services that enable connectivity between these groups of pods. Services enable the front end application to be made available to end users. It helps communication between back end and front end pods and helps in establishing connectivity to an external data source. Thus, services enable loose coupling between microservices in our application.

Introduction to Kubernetes Networking | My Public Notepad explains how pods communicate with each other through internal networking. We now need to cover external communication.

Let's assume we deployed a pod, having a web application running on it. How does an external user access the web page? First of all, let's look at the existing setup:
  • The Kubernetes node has an IP address e.g.
  • Our laptop is on the same network as well, so it has an IP address e.g. 192.168 1.10
  • The internal pod network is in the range
  • The pod has an IP
We cannot ping or access the pod at address from our laptop as it is in a separate network.

If we SSH into the Kubernetes node at from, we would be able to access the pod's web page by using curl Or if the node has a GUI, we would fire up a browser and see the web page in a browser following the address But this is from inside the Kubernetes node, and that's not what we really want.

We want to be able to access the web server from our laptop without having to SSH into the node and simply by accessing the IP of the Kubernetes node. So we need something in the middle to help us map requests to the node from our laptop through the node to the pod running the web container. This is where the Kubernetes service comes into play.

The Kubernetes service is a Kubernetes object, just like pods, replica set or deployments. There are several kinds of services:
  • NodePort service opens a port on the node, listens on it and forwards requests on that port to the port on the pod running the web application. It makes an internal pod accessible on a port on the node. More info: Kubernetes NodePort Service | My Public Notepad
  • Cluster IP service creates a virtual IP inside the cluster to enable communication between different services, such as a set of frontend servers to a set of backend servers.
  • Load balancer provisions a load balancer for our application in supported cloud providers. A good example of that would be to distribute load across the different web servers in your front end tier.

No comments: