Navigating Kubernetes Services Load Balancers

The way applications are hosted has changed over the years due to scalable and powerful Kubernetes architecture. Application downtime can be significantly decreased using Kubernetes. Whether it’s unplanned hardware related downtime or deployment of a software release, Kubernetes serves as a favorable option.

Kubernetes Service: Introduction

To learn about the Kubernetes services it’s important to understand the concepts of pods. Pods are temporary locations in Kubernetes where applications live. A pod is assigned a new IP address every time it’s launched. With every new deployment new pods are destroyed and recreated dynamically. To track the IP addresses of all the active pods Kubernetes services are used. Without Kubernetes services, it would have been a difficult task and it would increase the risk of application downtime.

Kubernetes service maps one or more pods by creating an abstraction. It allows applications to connect to the service using the service name. This removes the condition for other applications to know the IP addresses assigned to the pods. Similarly, the end-users and external applications can also access the service as they are exposed to the public through the Internet.

As an example of the service definition let’s expose the pods with the label app=redis to a service redis-service using TCP port 6397

The selector is responsible for mapping the service correctly to the corresponding pods. Here when a service gets a matching pod, it updates the IP address of the pod to the Endpoint. Endpoint is a Kubernetes object that keeps the record of the IP address of all the matching pods and updates its list automatically. Endpoint objects are created by each service.

In our example of Redis we can observe a line called Endpoints which refers to the list of pods’ IP addresses.

The endpoint objects are going to have the same name as that of the service.

It is a common way of defining a service and keeps in mind that Endpoints maintains a list of up-to-date IP addresses and this list is used by the service.

We can also define a service without the selector. For example, if we migrate our application to Kubernetes, we can evaluate how it behaves without migrating the Redis server. We want to use the existing Redis server, which is still in the old server. In such a scenario, we create a service as shown below:

Service can also be defined without using a selector. Let’s take an example of the scenario where we have migrated a new application to Kubernetes. We don’t want to observe how the application behaves without migrating to the Redis server. To use the existing Redis server which is in the old server service can be used.

Create a service using the following code:

Related posts

Optimizing Kafka Consumers with Kubernetes and KEDA

Optimizing Kafka Consumers with Kubernetes and KEDA

Establishing Static Code Analysis Using SonarQube

Establishing Static Code Analysis Using SonarQube

Kubernetes Workload

Kubernetes Workload

How to Deal with Memory Pressure in Redis

How to Deal with Memory Pressure in Redis

CDN Comparison: Amazon, Alibaba Cloud, IBM, Google Cloud, and Microsoft Azure

CDN Comparison: Amazon, Alibaba Cloud, IBM, Google Cloud, and Microsoft Azure