Scaling and upgrades
Add brokers, rebalance partitions with Cruise Control, keep older records on tiered storage, and upgrade Kafka with a rolling restart.
A Kafka cluster grows by adding brokers and moving partitions, not by giving the existing brokers a larger disk and hoping. It upgrades one broker at a time, while producers keep writing. This lab does both on the lab cluster, and it moves cold data to object storage so the broker disk holds the recent log.
The alerts from monitoring should stay quiet except for the under-replication you expect while a broker is rolling. If they do not recover, stop.
Prerequisites
- The
labcluster, three brokers, topics at replication factor 3 - A storage class with room for one more broker volume
- For tiered storage, an S3-compatible bucket. OpenShift Data Foundation is the one in our lab
- A maintenance window you can roll brokers in. Producers with
acks=allwill pause if you drop belowmin.insync.replicas
Add a broker
Raise the broker pool. The controller pool stays at three. A fourth controller does not make the cluster faster, and KRaft wants an odd count.
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaNodePool
metadata:
name: broker
labels:
strimzi.io/cluster: lab
spec:
replicas: 4
roles: [broker]
oc apply -f broker-pool.yaml
oc wait kafka/lab -n kafka --for=condition=Ready --timeout=900s
oc get pods -n kafka -l strimzi.io/pool-name=broker
The new broker is empty. Existing partitions stay where they were until something moves them. Cruise Control computes a move. Enable it on the Kafka resource with spec.cruiseControl: {}, let the operator start it, then propose a rebalance:
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaRebalance
metadata:
name: add-broker
namespace: kafka
labels:
strimzi.io/cluster: lab
spec: {}
When the resource reports ProposalReady, read the proposal. It lists partition moves. If you accept it:
oc annotate kafkarebalance add-broker -n kafka strimzi.io/rebalance=approve
The cluster stays available during the move. Replication traffic goes up. Do this when the produce rate has room, not at the top of the payroll run. A proposal you do not like is rejected with strimzi.io/rebalance=refresh, after you change the goals. The default goals spread replicas across brokers and respect rack. Set spec.kafka.rack.topologyKey before you care about zones, or the proposal has no zone to respect.
Adding partitions to a topic is a different knob, and topic design explains why it changes key placement. New brokers do not require new partitions.
Tiered storage
Local retention is how long the log stays on the broker disk. Topic retention is how long a consumer can still read it. Tiered storage puts the middle on object storage. A consumer reading an old offset does not need to know. The broker fetches the segment.
Enable it on the Kafka resource once the RemoteStorageManager plugin for your bucket is on the broker image. Keep local retention shorter than topic retention:
spec:
kafka:
config:
remote.log.storage.system.enable: "true"
log.retention.hours: "168"
log.local.retention.hours: "24"
tieredStorage:
type: custom
remoteStorageManager:
className: io.aiven.kafka.tieredstorage.RemoteStorageManager
classPath: /opt/kafka/plugins/tiered-storage/*
config:
storage.backend.class: io.aiven.kafka.tieredstorage.storage.s3.S3Storage
storage.s3.bucket.name: kafka-logs
storage.s3.region: us-east-1
storage.s3.path.style.access.enabled: "true"
Set the endpoint to the cluster's S3-compatible Service. Confirm a consumer can read an offset older than 24 hours after the local segment has gone. If it cannot, the plugin is not on the classpath or the bucket policy is wrong, and you should turn remote.log.storage.system.enable back off before retention deletes the only copy.
Tiered storage is not a backup. A deleted topic deletes the remote segments too. DC/DR is the copy in another site.
A rolling upgrade
Set spec.kafka.version to the new version the operator supports, one step at a time, along the path the operator documents. Apply, and watch:
oc get kafka lab -n kafka -w
oc get pods -n kafka -l strimzi.io/cluster=lab
The operator restarts one broker at a time and waits for it to rejoin the in-sync replicas. Producers with retries ride through that. A producer with acks=all and no retries will surface errors. Fix the producer before the upgrade, not during it.
After the cluster is Ready on the new version, move metadataVersion forward if the operator left it behind. Do that as a separate apply, once you are sure you will not roll the version back. A metadata downgrade is the step that fails.
Upgrade clients and Connect workers after the brokers, on the versions the release notes allow. The Connect image from Kafka Connect has its own version field. Keep it on a version the brokers accept.
What's next
- Watch under-replicated partitions during the roll, with the alert in monitoring.
- A second site, rather than a bigger disk, is DC/DR with MirrorMaker 2.
- The partition count you wish you had chosen is still topic design. Do it before the topic is full of keys.