This guide explains how to perform horizontal scaling (scale-out and scale-in) on a ZooKeeper cluster managed by KubeBlocks.
ZooKeeper Quorum Requirements
ZooKeeper uses a quorum-based consensus algorithm. For correct operation:
Before proceeding, verify your environment meets these requirements:
kubectl v1.21+ installed and configured with cluster accessExpected Workflow:
Updating to RunningScale out the ZooKeeper cluster by adding 2 replicas (from 3 to 5):
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: zk-scale-out
namespace: demo
spec:
clusterName: zookeeper-cluster
type: HorizontalScaling
horizontalScaling:
- componentName: zookeeper
scaleOut:
replicaChanges: 2
Apply it:
kubectl apply -f https://raw.githubusercontent.com/apecloud/kubeblocks-addons/refs/heads/main/examples/zookeeper/scale-out.yaml
Monitor the progress:
kubectl get ops zk-scale-out -n demo -w
NAME TYPE CLUSTER STATUS PROGRESS AGE
zk-scale-out HorizontalScaling zookeeper-cluster Running 0/2 8s
zk-scale-out HorizontalScaling zookeeper-cluster Running 1/2 2m11s
zk-scale-out HorizontalScaling zookeeper-cluster Running 2/2 4m9s
zk-scale-out HorizontalScaling zookeeper-cluster Succeed 2/2 4m33s
Update the replicas field in the Cluster resource:
kubectl patch cluster zookeeper-cluster -n demo --type=json \
-p='[{"op": "replace", "path": "/spec/componentSpecs/0/replicas", "value": 5}]'
kubectl get pods -n demo -l app.kubernetes.io/instance=zookeeper-cluster -L kubeblocks.io/role
NAME READY STATUS RESTARTS AGE ROLE
zookeeper-cluster-zookeeper-0 2/2 Running 0 6m12s follower
zookeeper-cluster-zookeeper-1 2/2 Running 0 6m58s follower
zookeeper-cluster-zookeeper-2 2/2 Running 0 7m41s leader
zookeeper-cluster-zookeeper-3 2/2 Running 0 4m9s follower
zookeeper-cluster-zookeeper-4 2/2 Running 0 4m33s follower
Expected Workflow:
Updating to RunningScale in the ZooKeeper cluster by removing 2 replicas (from 5 to 3):
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: zk-scale-in
namespace: demo
spec:
clusterName: zookeeper-cluster
type: HorizontalScaling
horizontalScaling:
- componentName: zookeeper
scaleIn:
replicaChanges: 2
Apply it:
kubectl apply -f https://raw.githubusercontent.com/apecloud/kubeblocks-addons/refs/heads/main/examples/zookeeper/scale-in.yaml
Monitor progress:
kubectl get ops zk-scale-in -n demo -w
NAME TYPE CLUSTER STATUS PROGRESS AGE
zk-scale-in HorizontalScaling zookeeper-cluster Running 0/2 8s
zk-scale-in HorizontalScaling zookeeper-cluster Running 1/2 47s
zk-scale-in HorizontalScaling zookeeper-cluster Running 2/2 88s
zk-scale-in HorizontalScaling zookeeper-cluster Succeed 2/2 2m4s
kubectl patch cluster zookeeper-cluster -n demo --type=json \
-p='[{"op": "replace", "path": "/spec/componentSpecs/0/replicas", "value": 3}]'
kubectl get pods -n demo -l app.kubernetes.io/instance=zookeeper-cluster -L kubeblocks.io/role
NAME READY STATUS RESTARTS AGE ROLE
zookeeper-cluster-zookeeper-0 2/2 Running 0 8m21s follower
zookeeper-cluster-zookeeper-1 2/2 Running 0 9m7s follower
zookeeper-cluster-zookeeper-2 2/2 Running 0 9m50s leader
kubectl delete cluster zookeeper-cluster -n demo
kubectl delete ns demo