This guide explains how to decommission (take offline) specific Pods in Elasticsearch clusters managed by KubeBlocks. Decommissioning provides precise control over cluster resources while maintaining availability. Use this for workload rebalancing, node maintenance, or addressing failures.
In traditional StatefulSet-based deployments, Kubernetes lacks the ability to decommission specific Pods. StatefulSets ensure the order and identity of Pods, and scaling down always removes the Pod with the highest ordinal number (e.g., scaling down from 3 replicas removes Pod-2
first). This limitation prevents precise control over which Pod to take offline, which can complicate maintenance, workload distribution, or failure handling.
KubeBlocks overcomes this limitation by enabling administrators to decommission specific Pods directly. This fine-grained control ensures high availability and allows better resource management without disrupting the entire cluster.
Before proceeding, ensure the following:
kubectl create ns demo
namespace/demo created
KubeBlocks uses a declarative approach for managing Elasticsearch Clusters. Below is an example configuration for deploying a Elasticsearch Cluster with create a cluster with replicas for different roles.
Apply the following YAML configuration to deploy the cluster:
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: es-multinode
namespace: demo
spec:
terminationPolicy: Delete
componentSpecs:
- name: dit
componentDef: elasticsearch-8
serviceVersion: 8.8.2
configs:
- name: es-cm
variables:
# use key `roles` to specify roles this component assume
roles: data,ingest,transform
replicas: 3
disableExporter: false
resources:
limits:
cpu: "1"
memory: "2Gi"
requests:
cpu: "1"
memory: "2Gi"
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- name: master
componentDef: elasticsearch-8
serviceVersion: 8.8.2
configs:
- name: es-cm
variables:
# use key `roles` to specify roles this component assume
roles: master
replicas: 3
disableExporter: false
resources:
limits:
cpu: "1"
memory: "2Gi"
requests:
cpu: "1"
memory: "2Gi"
volumeClaimTemplates:
- name: data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
Monitor the cluster status until it transitions to the Running state:
kubectl get cluster es-multinode -n demo -w
Expected Output:
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
es-multinode Delete Creating 10s
es-multinode Delete Updating 41s
es-multinode Delete Running 42s
Check the pod status and roles:
kubectl get pods -l app.kubernetes.io/instance=es-multinode -n demo
Expected Output:
NAME READY STATUS RESTARTS AGE
es-multinode-dit-0 3/3 Running 0 6m21s
es-multinode-dit-1 3/3 Running 0 6m21s
es-multinode-dit-2 3/3 Running 0 6m21s
es-multinode-master-0 3/3 Running 0 6m21s
es-multinode-master-1 3/3 Running 0 6m21s
es-multinode-master-2 3/3 Running 0 6m21s
Once the cluster status becomes Running, your Elasticsearch cluster is ready for use.
If you are creating the cluster for the very first time, it may take some time to pull images before running.
Expected Workflow:
onlineInstancesToOffline
is removedUpdating
to Running
To decommission a specific Pod (e.g., 'es-multinode-dit-1'), you can use one of the following methods:
Option 1: Using OpsRequest
Create an OpsRequest to mark the Pod as offline:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: es-multinode-decommission-ops
namespace: demo
spec:
clusterName: es-multinode
type: HorizontalScaling
horizontalScaling:
- componentName: dit
scaleIn:
onlineInstancesToOffline:
- 'es-multinode-dit-1' # Specifies the instance names that need to be taken offline
Check the progress of the decommissioning operation:
kubectl get ops es-multinode-decommission-ops -n demo -w
Example Output:
NAME TYPE CLUSTER STATUS PROGRESS AGE
es-multinode-decommission-ops HorizontalScaling es-multinode Running 0/1 8s
es-multinode-decommission-ops HorizontalScaling es-multinode Running 1/1 31s
es-multinode-decommission-ops HorizontalScaling es-multinode Succeed 1/1 31s
Option 2: Using Cluster API
Alternatively, update the Cluster resource directly to decommission the Pod:
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: dit
replicas: 2 # explected replicas after decommission
offlineInstances:
- es-multinode-dit-1 # <----- Specify Pod to be decommissioned
...
After applying the updated configuration, verify the remaining Pods in the cluster:
kubectl get pods -n demo -l app.kubernetes.io/instance=es-multinode,apps.kubeblocks.io/component-name=dit
Example Output:
NAME READY STATUS RESTARTS AGE
es-multinode-dit-0 2/2 Running 0 24m
es-multinode-dit-2 2/2 Running 0 2m1s
Key takeaways:
This provides granular cluster management while maintaining availability.