KubeBlocks
BlogsEnterprise
⌘K
​
Blogs
Overview
Quickstart
Architecture

Operations

Lifecycle Management
Vertical Scaling
Horizontal Scaling
Volume Expansion
Manage Kafka Services
Decommission Kafka Replica

Monitoring

Observability for Kafka Clusters

tpl

  1. Resource Hierarchy
  2. Containers Inside Each Pod
  3. KRaft Mode: No ZooKeeper Required
  4. Partition Leader Election
  5. Traffic Routing
  6. Automatic Failover

Kafka Architecture in KubeBlocks

This page describes how KubeBlocks deploys an Apache Kafka cluster on Kubernetes — covering the resource hierarchy, pod internals, KRaft-based consensus, and traffic routing.

Resource Hierarchy

KubeBlocks models a Kafka cluster as a hierarchy of Kubernetes custom resources:

Cluster  →  Component  →  InstanceSet  →  Pod × N
ResourceRole
ClusterUser-facing declaration — specifies topology, broker count, controller count, storage, and resources
ComponentGenerated automatically; references a ComponentDefinition describing container specs, lifecycle actions, and services
InstanceSetKubeBlocks custom workload (replaces StatefulSet); manages pods with stable identities and role awareness
PodActual running Kafka node; each pod gets a unique ordinal and its own PVC

KubeBlocks supports Kafka in KRaft mode (Kafka Raft Metadata), which eliminates the dependency on an external ZooKeeper ensemble. Nodes can serve as brokers, controllers, or combined (both roles) depending on the chosen topology.

Containers Inside Each Pod

Every Kafka pod runs three containers:

ContainerPortPurpose
kafka9092 (broker plaintext), 9093 (controller quorum)Kafka node serving producer/consumer traffic and/or participating in KRaft metadata consensus
kbagent5001Role probe endpoint — KubeBlocks queries GET /v1.0/getrole periodically
metrics-exporter9187Prometheus metrics exporter (JMX-based)

Each pod mounts its own PVC for the Kafka log directory (/var/lib/kafka/data), providing independent persistent storage per broker.

KRaft Mode: No ZooKeeper Required

Since Kafka 3.3 (KIP-833), the KRaft metadata quorum fully replaces ZooKeeper. KubeBlocks deploys Kafka exclusively in KRaft mode:

KRaft ConceptDescription
Controller quorumA set of controller nodes runs Raft consensus to manage cluster metadata (topic configs, partition assignments, ISR lists)
Active controllerThe Raft leader among controllers; all metadata writes go through it
BrokerStores partition log data and serves producer/consumer requests; fetches metadata from the active controller
Combined nodeRuns both controller and broker roles; suitable for smaller clusters
Metadata logAn internal Kafka topic (__cluster_metadata) replicated by the controller quorum; brokers tail this log to stay current

The controller quorum requires a majority of controller nodes to be available for metadata operations. A quorum of 3 controllers tolerates 1 failure; 5 controllers tolerate 2.

Partition Leader Election

Kafka data availability is governed by per-partition leader election:

ConceptDescription
Partition leaderThe single broker responsible for all reads and writes for a given partition
Follower replicasBrokers that replicate from the leader; form the In-Sync Replica (ISR) set
ISR (In-Sync Replicas)Replicas fully caught up with the leader; only ISR members are eligible to become leader
Leader electionWhen the leader broker fails, the active controller selects a new leader from the ISR set
Unclean leader electionDisabled by default; enabling it risks data loss but speeds recovery when the ISR is empty

Traffic Routing

KubeBlocks creates two services for each Kafka cluster:

ServiceTypePortsSelector
{cluster}-kafka-brokerClusterIP9092 (broker)all broker pods
{cluster}-kafka-headlessHeadless9092, 9093all pods

Kafka clients initially connect to any broker (via the ClusterIP service) to fetch cluster metadata, then connect directly to partition leaders using the headless service addresses. Each broker advertises its stable pod DNS name as its listener address so clients can route directly:

{pod-name}.{cluster}-kafka-headless.{namespace}.svc.cluster.local:9092

Automatic Failover

When a Kafka broker or controller fails:

  1. Broker failure — the active controller detects the broker's session timeout and removes it from ISR lists
  2. Partition leader election — for each partition where the failed broker was leader, the controller elects a new leader from the remaining ISR members
  3. Producer/consumer continuity — clients refresh metadata and reconnect to new partition leaders; brief retries are normal
  4. Controller failure — if a controller node fails, the remaining controller quorum elects a new active controller via Raft within seconds
  5. KubeBlocks recovery — KubeBlocks restarts the failed pod; on startup, the broker fetches metadata from the controller quorum and resumes replication

© 2026 KUBEBLOCKS INC