Kubernetes Services Explained😎

Julius Omoleye
3 min readOct 18, 2022

--

Kubernetes Services can be very overwhelming for beginners just learning Kubernetes. First of all, let us start by understanding what a Kubernetes service is.

From the Kubernetes Documentation, A service is an Abstract way in which we expose an application running on a set of pods as a network service. What this simply means is a service in Kubernetes exposes(makes available) running containers on a set of Pods.

Without Services, we won’t be able to access the containers running on pods externally(This is true and false at the same time, lol). In Kubernetes, we have different Services namely: ClusterIP, NodePort, LoadBalancer, and ExternalName. The services serve different purposes and also it is worthy to note that some objects are built on some other objects. Before we jump into the explanations of the objects/services, let’s take note of the following points,

  • Services Points to Pods and they do not point to deployments or ReplicaSets
  • The services points to Pods directly using labels(labels defined in the pod/replicaSet/deployment definition file.
  • Nodes have external and internal IP addresses while Pods only have an Internal IP address.
  • In Kubernetes, all pods can reach each other using their internal IP address no matter which nodes they are running on in the cluster.
  • It is not advisable to use the internal IP of a Pod because of its ephemeral nature i.e lasting for a very short time. In a clearer manner, they get destroyed and another Pod is created with a new IP assigned . In other to avoid any Fiasco, we create a Service.
  • A service is not scheduled on specific node

Now that we understand some more things about pods and services lets understand the service objects.

  1. ClusterIP: The ClusterIP service makes the Pod available inside the cluster, via a name and an IP. With a ClusterIP 2 different Pods can safely connect with each other in a cluster.
  2. NodePort: This service is built on the ClusterIP service and I want you to look at it that, whenever a nodePort is created, it creates a clusterIP service, even though there is no ClusterIP object created. when a nodePort object/service is created, the internal service created in the cluster will now be reachable from every node’s internal and external IP address on the port set in the YAML definition file or from the command line.
  3. LoadBalancer: We use the LoadBalancer service if we want to be able to access the whole of the cluster from a single endpoint. The LoadBalancer service creates a single IP address and distributes requests to all the external node IP addresses. Hence it is built on the nodePort Service. The LoadBalancer service creates a NodePort service and sends a message to the provider hosting the Kubernetes Cluster asking for a LoadBalancer to be set up pointing to all external node IPs and specific node Port. Let me quickly mention that minikube doesn’t support LoadBalancer Service directly, but there’s a way around it, Kindly check the minikube documentation for more assistance.
  4. ExternalName: When you create this type of service, it creates an internal service with an endpoint pointing to a DNS name. This service is used when one Pod/container in our cluster wants to connect with another application/container in a remote server/location.

That will be all for now, if you got any questions about the article, Kindly reach out to me on Twitter here or visit the Kubernetes documentation.

Thanks for reading!!!

--

--

Julius Omoleye
Julius Omoleye

Written by Julius Omoleye

Backend Systems and Devops with Python 🦄 AI and ML freak👻

No responses yet