skills/kubeblocks-horizontal-scaling/SKILL.md
Scale database cluster replicas or shards horizontally with KubeBlocks via OpsRequest. Supports scale-out (add replicas), scale-in (remove replicas), decommissioning specific instances, and shard scaling for Redis Cluster and MongoDB sharded topologies. Use when the user wants to add or remove replicas, nodes, instances, or shards. NOT for changing CPU/memory (see vertical-scaling) or expanding disk (see volume-expansion).
npx skillsauth add apecloud/kubeblocks-skills kubeblocks-horizontal-scalingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Horizontal scaling changes the number of replicas (or shards) in a KubeBlocks database cluster. KubeBlocks supports scale-out (add replicas) and scale-in (remove replicas), including decommissioning specific instances and adjusting shard counts for sharded clusters (Redis Cluster, MongoDB sharded).
Official docs: https://kubeblocks.io/docs/preview/user_docs/kubeblocks-for-mysql/cluster-management/scale-a-mysql-cluster Full doc index: https://kubeblocks.io/llms-full.txt
Consensus-based topologies (MySQL Group Replication, Kafka KRaft controllers) require an odd number of replicas (minimum 3) because Raft/Paxos protocols need a majority quorum to elect a leader. With 3 replicas, the system tolerates 1 failure; with 2 replicas, any single failure breaks quorum and the cluster becomes unavailable.
Before proceeding, verify the cluster is healthy and no other operation is running:
# Cluster must be Running
kubectl get cluster <cluster-name> -n <namespace> -o jsonpath='{.status.phase}'
# No pending OpsRequests
kubectl get opsrequest -n <namespace> -l app.kubernetes.io/instance=<cluster-name> --field-selector=status.phase!=Succeed
If the cluster is not Running or has a pending OpsRequest, wait for it to complete before proceeding.
Check the current replica count:
kubectl get cluster <cluster-name> -n <namespace> -o yaml | grep replicas
- [ ] Step 1: Check current replicas
- [ ] Step 2: Apply horizontal scaling OpsRequest
- [ ] Step 3: Monitor the operation
- [ ] Step 4: Verify new topology
kubectl get cluster <cluster-name> -n <namespace> -o yaml | grep replicas
Or list pods:
kubectl get pods -n <namespace> -l app.kubernetes.io/instance=<cluster-name>
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scaleout-<cluster-name>
namespace: <namespace>
spec:
clusterName: <cluster-name>
type: HorizontalScaling
horizontalScaling:
- componentName: <component-name>
scaleOut:
replicaChanges: <number-to-add>
Example — add 2 replicas to a MySQL cluster.
Before applying, validate with dry-run:
kubectl apply -f - --dry-run=server <<'EOF'
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scaleout-mysql-cluster
namespace: default
spec:
clusterName: mysql-cluster
type: HorizontalScaling
horizontalScaling:
- componentName: mysql
scaleOut:
replicaChanges: 2
EOF
If dry-run reports errors, fix the YAML before proceeding.
kubectl apply -f - <<'EOF'
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scaleout-mysql-cluster
namespace: default
spec:
clusterName: mysql-cluster
type: HorizontalScaling
horizontalScaling:
- componentName: mysql
scaleOut:
replicaChanges: 2
EOF
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scalein-<cluster-name>
namespace: <namespace>
spec:
clusterName: <cluster-name>
type: HorizontalScaling
horizontalScaling:
- componentName: <component-name>
scaleIn:
replicaChanges: <number-to-remove>
Example — remove 1 replica from a PostgreSQL cluster.
Before applying, validate with dry-run:
kubectl apply -f - --dry-run=server <<'EOF'
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scalein-pg-cluster
namespace: default
spec:
clusterName: pg-cluster
type: HorizontalScaling
horizontalScaling:
- componentName: postgresql
scaleIn:
replicaChanges: 1
EOF
If dry-run reports errors, fix the YAML before proceeding.
kubectl apply -f - <<'EOF'
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scalein-pg-cluster
namespace: default
spec:
clusterName: pg-cluster
type: HorizontalScaling
horizontalScaling:
- componentName: postgresql
scaleIn:
replicaChanges: 1
EOF
To remove a specific pod instead of the last one, use onlineInstancesToOffline:
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scalein-specific-<cluster-name>
namespace: <namespace>
spec:
clusterName: <cluster-name>
type: HorizontalScaling
horizontalScaling:
- componentName: <component-name>
scaleIn:
replicaChanges: 1
onlineInstancesToOffline:
- "<pod-name>"
Example — decommission a specific MongoDB replica.
Before applying, validate with dry-run:
kubectl apply -f - --dry-run=server <<'EOF'
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scalein-specific-mongo
namespace: default
spec:
clusterName: mongo-cluster
type: HorizontalScaling
horizontalScaling:
- componentName: mongodb
scaleIn:
replicaChanges: 1
onlineInstancesToOffline:
- "mongo-cluster-mongodb-2"
EOF
If dry-run reports errors, fix the YAML before proceeding.
kubectl apply -f - <<'EOF'
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scalein-specific-mongo
namespace: default
spec:
clusterName: mongo-cluster
type: HorizontalScaling
horizontalScaling:
- componentName: mongodb
scaleIn:
replicaChanges: 1
onlineInstancesToOffline:
- "mongo-cluster-mongodb-2"
EOF
For sharded topologies, use the shards field to change the number of shard groups:
apiVersion: apps.kubeblocks.io/v1beta1
kind: OpsRequest
metadata:
name: scale-shards-<cluster-name>
namespace: <namespace>
spec:
clusterName: <cluster-name>
type: HorizontalScaling
horizontalScaling:
- componentName: <component-name>
scaleOut:
replicaChanges: <shards-to-add>
Note: For Redis Cluster and MongoDB sharded topologies, each "replica" in the component represents a shard group. Increasing replicas adds new shards and triggers data rebalancing automatically.
For simple replica count changes, you can also patch the cluster directly:
kubectl patch cluster <cluster-name> -n <namespace> \
--type merge -p '{"spec":{"componentSpecs":[{"name":"<component-name>","replicas":<new-total>}]}}'
Example — set MySQL replicas to 5:
kubectl patch cluster mysql-cluster -n default \
--type merge -p '{"spec":{"componentSpecs":[{"name":"mysql","replicas":5}]}}'
kubectl get ops -n <namespace> -w
Success condition:
.status.phase=Succeed| Typical: 1-5min | If stuck >10min:kubectl describe ops <ops-name> -n <namespace>
Expected progression: Pending → Running → Succeed.
Watch pods:
kubectl get pods -n <namespace> -l app.kubernetes.io/instance=<cluster-name> -w
Success condition:
.status.phase=Running| Typical: 1-5min | If stuck >10min:kubectl describe pod <pod-name> -n <namespace>
kubectl get cluster <cluster-name> -n <namespace> -o yaml | grep replicas
Confirm pod count:
kubectl get pods -n <namespace> -l app.kubernetes.io/instance=<cluster-name>
Scale-out pods stuck in Pending:
kubectl describe pod <pod-name> -n <namespace>kubectl get scScale-in fails:
kubectl describe ops <ops-name> -n <namespace>Data rebalancing after shard scaling:
redis-cli --cluster check.For general agent safety conventions (dry-run, status confirmation, production protection), see safety-patterns.md.
For engine-specific scaling behaviors, minimum replica constraints, replicas vs shards comparison, and decommissioning patterns, see reference.md.
devops
Expand persistent volume storage for KubeBlocks database clusters via OpsRequest. Requires the StorageClass to support volume expansion (allowVolumeExpansion=true). Use when the user needs more disk space, wants to increase storage, expand volumes, or resize PVCs. NOT for changing CPU/memory (see vertical-scaling) or adding more replicas (see horizontal-scaling). Note that volume shrinking is not supported by Kubernetes.
data-ai
Scale CPU and memory resources for KubeBlocks database clusters via OpsRequest (vertical scaling). Supports in-place updates when the feature gate is enabled. Use when the user wants to change, increase, decrease, resize, or adjust CPU or memory resources of a database cluster. NOT for adding/removing replicas or shards (see horizontal-scaling) or expanding disk storage (see volume-expansion).
data-ai
Upgrade the KubeBlocks operator itself via Helm. Covers update operator, upgrade to v1.0, update kubeblocks version, and CRD updates. Use when the user wants to upgrade KubeBlocks, update the operator, or upgrade to a new KubeBlocks release. NOT for upgrading database engine versions (see minor-version-upgrade).
development
Diagnostic guide for KubeBlocks-managed database clusters. Use when the user reports troubleshoot, debug, diagnose, not working, error, failed, stuck, CrashLoopBackOff, cluster exception, or similar problems with their database cluster. This skill guides the agent through diagnostic steps — it does NOT perform actions.