K8s pt.6 / What composes DB in Kubernetes?

Liebertar
Dev-ops
Published in
5 min readMar 9, 2024

Now let’s talk about the way how to manage the data in Kubernetes. It’s super important to catch the basics of what makes up a database. So, in this conversation, we’ll keep it simple and explore the essential components used to build the database management process in Kubernetes.

As we unpack the secrets of safeguarding our digital lives in the face of data disasters yet, we’ll save that discussion for the next part.

“Let’s Unbox Your Lunch.

What are in your Cluster for Data Storing?”

1. Pod (Flash Storage):

Imagine pods as dynamic lunchboxes that hold data for short periods. Just like our lunchboxes might be swapped for a fresh one due to health considerations, pods might be reborn for better performance or other reasons. This highlights the challenge — when the lunchbox (pod) is no longer present, all the snacks (data) inside disappear!

  • Example : Consider a pod as your lunchbox. Inside of it, there are separate sections (containers) holding different snacks (data) for a quick break or task.

2. Volumes (Persistent Storage):

Now, envision volumes as a robust library bookshelf, a reliable repository for your valuable data. This bookshelf remains steadfast, safeguarding your favorite books (data) even when your lunchbox (pod) decides to take a break or embark on a short vacation!

  • Example : Visualize volumes as a bookshelf in a library. Each shelf is like a secure space where many lunchboxes (pods) can store and share their favorite books (data) without worry.

3. Not as a name of DISK or Storage?

I guess the concept of “Volume” can seem abstract. In practical use, it involves storing data outside the cluster, and this external storage can take different forms depending on the platform you’re using.

  • AWS (Amazon Web Services) : On AWS, you could consider solutions like Elastic Block Store (EBS) or Amazon S3 for your external storage needs. Think of these as additional storage rooms for your Kubernetes data, conveniently located outside the main living space.
  • Microsoft Azure (Azure Kubernetes Service) : In the Azure cloud environment as well, external storage for volumes in Kubernetes includes Azure Disk or Azure Files. These are like extra cupboards outside your kitchen (cluster), accessible and reliable.

4. Sum Up.

Pod Image (mongd or any other DB image) and Volumes are reliable partners. They collaborate to create a shared strategy, making sure everyone’s favorite books (data) are kept safe and can be easily accessed.

Sometimes, your lunchbox (pod) needs a break, or it might not stick around forever. Even though the library bookshelf (volumes) is great, we still need a backup plan to keep things safe when the lunchbox isn’t there anymore. It’s like having a spare shelf for your favorite books when you go on a school adventure or a break.

“PVs and PVCs : What Makes Up Your Storage Volume”

1. Persistent Volumes (PV):

PVs, or Persistent Volumes, are like storage rooms in our building. They play a crucial role in providing persistent and cluster-wide storage. Each PV is essentially a reserved space that comes with a specific amount of storage capacity.

  • Example: Imagine PVs as individual storage rooms within your building. Each room is designated for specific purposes, offering a set amount of space that applications can consistently rely on.

2. Persistent Volume Claim

Now, think of PVCs, or Persistent Volume Claims, as residents in our building submitting requests for storage space. These requests are sent to available PVs, specifying the amount and type of storage they need.

  • Example: Let’s say PVCs as residents filling out requests for storage space tailored to their unique needs. It’s similar to individuals in the building specifying the size and type of storage room they require, ensuring a personalized and efficient allocation of resources.

“Strategic Point : Managing Data in Kubernetes with PVs and PVCs”

Now Let’s shortly look into the smart way of handling data in Kubernetes through PVs (Persistent Volumes) and PVCs (Persistent Volume Claims).

1. Lifecycle Management:

Explore the journey of PVs and PVCs, from their creation to when it’s time to bid them farewell. Understand how these components evolve over time, ensuring a seamless data management lifecycle.

2. Real-World Scenario:

Imagine you’re running a website, and you need a reliable way to store user data. Enter PVs and PVCs — like the backstage crew ensuring your data is always ready for the spotlight. Think of PVs as reserved storage spaces, and PVCs as tickets users claim to access those spaces.

“Using Statefulset for DB : Why aren’t we using replicaset for this time?”

Imagine orchestrating a music festival with bands represented as stateful applications:

StatefulSets ensure each band (pod with database image) keep its unique name (pod identity) as they move between stages (nodes). Bands perform in a specific order, maintained by StatefulSets for a seamless festival experience.

Persistent storage ensures instruments (data) are always there, just like having instruments ready for every performance.

And StatefulSets handle stage adjustments, allowing the addition or removal of stages (scaling) without disrupting the performance sequence.

image from https://www.nubersia.com/wp-content/uploads/2022/10/StatefulSets.jpg

1. Why StatefulSets for Databases :

Unlike using simple replicas, StatefulSets provide a unique identity to each pod, crucial for databases that require stable network identifiers. They ensure that as your database scales, each instance maintains its identity and order, preventing potential chaos that replicas might introduce. This stability is paramount for databases, making StatefulSets the preferred conductor for orchestrating reliable and orderly performances.

2. Sum up

When we work with YAML files and follow practical steps for our backup plan, StatefulSets play a crucial role in Kubernetes. They act like reliable conductors, providing stability, order, and persistence to our system. This helps ensure a reliable performance in the constantly changing world of technology. Just like a skilled conductor brings out the best in musicians, StatefulSets elevate our stateful applications, making them a masterpiece in the domain of Kubernetes orchestration.

03.07.24 — Fin.

--

--