K8s – Question3

Use context: kubectl config use-context k8s-c1-H

There are two Pods named o3db-* in Namespace project-c13. C13 management asked you to scale the Pods down to one replica to save resources.

Scaling Down a StatefulSet in Kubernetes

In Kubernetes, Pods are often managed by higher-level controllers like Deployments, DaemonSets, or StatefulSets. In this guide, we’ll walk through the process of identifying and scaling down a StatefulSet to satisfy a specific task.

Step 1: Identify the Pods and Their Managing Controller

First, let’s take a look at the running Pods. Here we see two replicas of the o3db Pod:

From the Pod names, it looks like these Pods are managed by a StatefulSet. However, to confirm this, we can check the common Kubernetes resources that manage Pods:

This confirms that the Pods are indeed managed by a StatefulSet. Alternatively, we could also look at the labels of the Pods to gather this information:

Step 2: Scale Down the StatefulSet

To meet the task’s requirement, we need to scale down the number of replicas in the StatefulSet o3db to one. This can be done using the following command:

Step 3: Verify the Scaling Operation

After scaling down, you can verify the current state of the StatefulSet with this command:

As shown above, the StatefulSet o3db now has one replica, and everything is functioning as expected. The management is happy again!

In this guide, we walked through how to identify the managing controller of a set of Pods, confirm it’s a StatefulSet, and scale it down. This is a common task in managing Kubernetes clusters, ensuring resources are used efficiently.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *