Stateful application — State management in Kubernetes in real-time.

Sujit Udhane
2 min readNov 6, 2021

Scenario: Ideally, in the modern era, applications (services/microservices) should be stateless. But, there are few scenarios that arise which force the applications to become stateful. Typical example is, you do have a tiny data set (going through less updates), you would like to hold onto a memory (like embedded cache) and you want to avoid a separate cache server to manage complexity of your infrastructure.

Challenge: In the Kubernetes world, if you keep on changing the number of pods (stateful application pods), managing the state data/information across different pods in real-time.

Solution: Creating a headless service.

A headless service is a service with a service IP but instead of load-balancing it will return the IPs of the associated Pods. This allows us to interact directly with the Pods instead of a proxy. It’s as simple as specifying None for .spec.clusterIP and can be utilized with or without selectors — you’ll see an example with selectors in a moment.

Below are Kubernetes artifacts

  1. Application deployment descriptor file

2. Application service descriptor file

3. Headless service descriptor file

Usage: Generally embedded cache solutions like Infinispan, Hazelcast, Redis can be managed through this way.

If you found the article useful, please clap.

References:
1.
https://dev.to/kaoskater08/building-a-headless-service-in-kubernetes-3bk8
2. https://kubernetes.io/docs/tutorials/stateful-application/cassandra/

--

--

Sujit Udhane

I am Lead Platform Architect, working in Pune-India. I have 20+ years of experience in technology, and last 10+ years working as an Architect.