This guide demonstrates how to vertically scale a Kafka 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 Kafka 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 Kafka Clusters. Below is an example configuration for deploying a Kafka Cluster with 3 components
Apply the following YAML configuration to deploy the cluster:
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: kafka-separated-cluster
namespace: demo
spec:
terminationPolicy: Delete
clusterDef: kafka
topology: separated_monitor
componentSpecs:
- name: kafka-broker
replicas: 1
resources:
limits:
cpu: "0.5"
memory: "0.5Gi"
requests:
cpu: "0.5"
memory: "0.5Gi"
env:
- name: KB_KAFKA_BROKER_HEAP
value: "-XshowSettings:vm -XX:MaxRAMPercentage=100 -Ddepth=64"
- name: KB_KAFKA_CONTROLLER_HEAP
value: "-XshowSettings:vm -XX:MaxRAMPercentage=100 -Ddepth=64"
- name: KB_BROKER_DIRECT_POD_ACCESS
value: "true"
volumeClaimTemplates:
- name: data
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
- name: metadata
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
- name: kafka-controller
replicas: 1
resources:
limits:
cpu: "0.5"
memory: "0.5Gi"
requests:
cpu: "0.5"
memory: "0.5Gi"
volumeClaimTemplates:
- name: metadata
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
- name: kafka-exporter
replicas: 1
resources:
limits:
cpu: "0.5"
memory: "1Gi"
requests:
cpu: "0.1"
memory: "0.2Gi"
These three components will be created strictly in controller->broker->exporter
order as defined in ClusterDefinition
.
Monitor the cluster status until it transitions to the Running state:
kubectl get cluster kafka-separated-cluster -n demo -w
Expected Output:
kubectl get cluster kafka-separated-cluster -n demo
NAME CLUSTER-DEFINITION TERMINATION-POLICY STATUS AGE
kafka-separated-cluster kafka Delete Creating 13s
kafka-separated-cluster kafka Delete Running 63s
Check the pod status and roles:
kubectl get pods -l app.kubernetes.io/instance=kafka-separated-cluster -n demo
Expected Output:
NAME READY STATUS RESTARTS AGE
kafka-separated-cluster-kafka-broker-0 2/2 Running 0 13m
kafka-separated-cluster-kafka-controller-0 2/2 Running 0 13m
kafka-separated-cluster-kafka-exporter-0 1/1 Running 0 12m
Once the cluster status becomes Running, your Kafka 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 kafka-broker component:
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
name: kafka-separated-cluster-vscale-ops
namespace: demo
spec:
clusterName: kafka-separated-cluster
type: VerticalScaling
verticalScaling:
- componentName: kafka-broker
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 kafka-separated-cluster-vscale-ops -w
Expected Result:
NAME TYPE CLUSTER STATUS PROGRESS AGE
kafka-separated-cluster-vscale-ops VerticalScaling kafka-separated-cluster Running 0/1 12s
kafka-separated-cluster-vscale-ops VerticalScaling kafka-separated-cluster Running 1/1 13s
kafka-separated-cluster-vscale-ops VerticalScaling kafka-separated-cluster Running 1/1 13s
kafka-separated-cluster-vscale-ops VerticalScaling kafka-separated-cluster Succeed 1/1 13s
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: kafka-broker
replicas: 1
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 kafka-separated-cluster -n demo
Expected Output:
Resources Allocation:
COMPONENT INSTANCE-TEMPLATE CPU(REQUEST/LIMIT) MEMORY(REQUEST/LIMIT) STORAGE-SIZE STORAGE-CLASS
kafka-broker 1 / 1 1Gi / 1Gi data:20Gi <none>
To remove all created resources, delete the Kafka Cluster along with its namespace:
kubectl delete cluster kafka-separated-cluster -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 Kafka Cluster remains performant and resilient.