This guide demonstrates how to vertically scale a Elasticsearch Cluster managed by KubeBlocks by adjusting compute resources (CPU and memory) while maintaining the same number of replicas.
Vertical scaling modifies compute resources (CPU and memory) for Elasticsearch instances while maintaining replica count. Key characteristics:
KubeBlocks ensures minimal impact during scaling operations by following a controlled, role-aware update strategy: Role-Aware Replicas (Primary/Secondary Replicas)
Role-Unaware Replicas (Ordinal-Based Scaling) If replicas have no defined roles, updates follow Kubernetes pod ordinal order:
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:
Updating
to Running
Option 1: Using VerticalScaling OpsRequest
Apply the following YAML to scale up the resources for the elasticsearch-broker component:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: es-multinode-vscale-ops
namespace: demo
spec:
clusterName: es-multinode
type: VerticalScaling
verticalScaling:
- componentName: dit
requests:
cpu: '1'
memory: 1Gi
limits:
cpu: '1'
memory: 1Gi
You can check the progress of the scaling operation with the following command:
kubectl -n demo get ops es-multinode-vscale-ops -w
Expected Result:
NAME TYPE CLUSTER STATUS PROGRESS AGE
es-multinode-vscale-ops VerticalScaling es-multinode Running 0/3 57s
es-multinode-vscale-ops VerticalScaling es-multinode Running 1/3 60s
es-multinode-vscale-ops VerticalScaling es-multinode Running 2/3 118s
es-multinode-vscale-ops VerticalScaling es-multinode Running 3/3 2m51s
es-multinode-vscale-ops VerticalScaling es-multinode Running 3/3 2m51s
es-multinode-vscale-ops VerticalScaling es-multinode Succeed 3/3 2m51s
Option 2: Direct Cluster API Update
Alternatively, you may update spec.componentSpecs.resources
field to the desired resources for vertical scale.
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
componentSpecs:
- name: dit
replicas: 3
resources:
requests:
cpu: "1" # Update the resources to your need.
memory: "1Gi" # Update the resources to your need.
limits:
cpu: "1" # Update the resources to your need.
memory: "1Gi" # Update the resources to your need.
...
Planning:
Execution:
Post-Scaling:
Verify the updated resources by inspecting the cluster configuration or Pod details:
kbcli cluster describe es-multinode -n demo
Expected Output:
Resources Allocation:
COMPONENT INSTANCE-TEMPLATE CPU(REQUEST/LIMIT) MEMORY(REQUEST/LIMIT) STORAGE-SIZE STORAGE-CLASS
dit 1 / 1 1Gi / 1Gi data:20Gi <none>
To remove all created resources, delete the Elasticsearch Cluster along with its namespace:
kubectl delete cluster es-multinode -n demo
kubectl delete ns demo
In this guide, you learned how to:
Vertical scaling is a powerful tool for optimizing resource utilization and adapting to changing workload demands, ensuring your Elasticsearch Cluster remains performant and resilient.