Apache Kafka — Event Streaming from Basics to a Platform Service›13 · Kafka on Kubernetes and managed Kafka

Lesson 13 of 17 · Operating Kafka

Kafka on Kubernetes and managed Kafka

Running Kafka on Kubernetes with the Strimzi operator: the Kafka, KafkaNodePool, KafkaTopic and KafkaUser resources, listeners and why advertised addresses matter, storage and node pools, spreading across zones, how the operator does rolling upgrades and certificate renewal, and Cruise Control for rebalancing. Then the managed options (Amazon MSK, Confluent Cloud, Azure Event Hubs) and how to choose between running it yourself and buying it.

Advanced
Key wordsKafka on KubernetesStrimzioperatorKafka custom resourceKafkaNodePoolKafkaTopicKafkaUserKafkaConnectKafkaMirrorMaker2Cruise Controllistenersinternalrouteloadbalancernodeportadvertised listenerspersistent volumesrack awarenesspod anti-affinityrolling upgradeAmazon MSKMSK ServerlessConfluent CloudAzure Event Hubsmanaged Kafka

Why Kafka is hard on Kubernetes, and how operators help

Kafka is stateful, identity-sensitive (each broker has an ID and a disk) and network-sensitive (clients talk to individual brokers). Plain Deployments don't fit. An operator encodes the operational knowledge: create brokers in order, keep their disks, restart one at a time only when safe, manage certificates, apply configuration changes.

Strimzi (a CNCF project) is the most widely used Kafka operator. It installs with Helm (strimzi-kafka-operator chart) and manages everything through custom resources.

The resources

apiVersion: kafka.strimzi.io/v1
kind: KafkaNodePool
metadata:
  name: controllers
  namespace: kafka
  labels: { strimzi.io/cluster: events }
spec:
  replicas: 3
  roles: [ controller ]
  storage:
    type: persistent-claim
    size: 20Gi
    class: fast-ssd
---
apiVersion: kafka.strimzi.io/v1
kind: KafkaNodePool
metadata:
  name: brokers
  namespace: kafka
  labels: { strimzi.io/cluster: events }
spec:
  replicas: 3
  roles: [ broker ]
  resources:
    requests: { cpu: "2", memory: 8Gi }
    limits:   { memory: 8Gi }
  storage:
    type: jbod
    volumes:
    - { id: 0, type: persistent-claim, size: 500Gi, class: fast-ssd, deleteClaim: false }
---
apiVersion: kafka.strimzi.io/v1
kind: Kafka
metadata:
  name: events
  namespace: kafka
spec:
  kafka:
    listeners:
    - { name: tls,  port: 9093, type: internal, tls: true, authentication: { type: tls } }
    - { name: ext,  port: 9094, type: loadbalancer, tls: true, authentication: { type: tls } }
    authorization:
      type: simple
    rack:
      topologyKey: topology.kubernetes.io/zone
    config:
      default.replication.factor: 3
      min.insync.replicas: 2
      offsets.topic.replication.factor: 3
      transaction.state.log.replication.factor: 3
      transaction.state.log.min.isr: 2
      auto.create.topics.enable: false
  entityOperator:
    topicOperator: {}
    userOperator: {}
  cruiseControl: {}
Part What it does
KafkaNodePool Groups of nodes with roles. Here: 3 dedicated KRaft controllers and 3 brokers with large SSD volumes
listeners How clients connect: internal for in-cluster, loadbalancer, nodeport, route or ingress for outside
authorization Turns on ACLs (lesson 14)
rack Uses the node's zone label so replicas spread across zones
config Normal broker settings: the durable defaults from lesson 8
entityOperator Topic Operator (manages KafkaTopic) and User Operator (manages KafkaUser, certificates, ACLs, quotas)
cruiseControl Enables partition rebalancing with KafkaRebalance resources

Teams then declare topics and users as resources, which fits GitOps perfectly. The hands-on project Kafka as a platform service with Strimzi builds exactly this on kind.

Listeners and advertised addresses

A client first connects to a bootstrap address, gets the cluster metadata, then connects directly to each partition leader using the address that broker advertises. If brokers advertise in-cluster DNS names (events-brokers-0.events-kafka-brokers.kafka.svc), clients outside Kubernetes get the metadata and then fail.

Strimzi's external listener types solve this by creating one bootstrap service plus one service per broker and advertising the right external addresses. With loadbalancer that means one cloud load balancer per broker, which costs money; ingress or route types use TLS passthrough with SNI to share one entry point.

The bootstrap address is like the reception desk of a big office: it hands you a map of which room each person sits in. If the map only says "room 3, inside the building", a visitor outside can't use it. External listeners make sure every room also has a door to the street printed on the map.

Storage and scheduling

  • Persistent volumes with fast SSDs; Kafka needs steady disk throughput more than huge IOPS.
  • JBOD (several volumes per broker) spreads partitions over disks; volumes can be added later.
  • Pod anti-affinity and the rack setting keep brokers on different nodes and zones.
  • Set memory requests equal to limits, and leave memory for the OS page cache: a 8 GiB pod might give Java 3–4 GiB of heap and leave the rest to the cache.
  • Never let deleteClaim: true near production data.

Operations the operator does for you

  • Rolling updates for configuration changes, version upgrades and certificate renewals: one pod at a time, and only when doing so won't drop any partition below min.insync.replicas.
  • Certificates: Strimzi runs its own cluster and client CAs, renews broker and user certificates before expiry, and can use your own CA.
  • Upgrades: change spec.kafka.version (and later metadataVersion) after upgrading the operator; the operator rolls the brokers.
  • Scaling brokers: add replicas to a node pool, then use Cruise Control (KafkaRebalance) to move partitions onto the new brokers. New brokers get no existing partitions by themselves.

The operator is now critical infrastructure

Pin the operator version, read its upgrade notes (supported Kafka versions change), upgrade it in a test cluster first, and monitor it. An operator that is down doesn't stop Kafka, but nothing gets created, renewed or repaired.

Managed Kafka

Option What you get Watch out for
Amazon MSK (provisioned) AWS runs brokers and KRaft; you choose instance types, storage and version; IAM or mTLS auth You still size, plan partitions, and handle client tuning; broker-hour pricing
MSK Serverless No sizing; pay per throughput and storage Per-cluster and per-partition limits; fewer settings
Confluent Cloud Fully managed Kafka plus Schema Registry, connectors, Flink, governance Higher price; vendor features beyond Apache Kafka
Azure Event Hubs (Kafka API) Kafka protocol on Azure's own service; no brokers at all Not real Kafka underneath: some features and admin APIs differ
Google Managed Service for Apache Kafka Managed Apache Kafka on GCP Check region and feature availability

Build or buy?

Choose self-managed (Strimzi) when… Choose managed when…
You need the same platform on several clouds or on-premises You run mainly on one cloud
You need full control of versions, configuration and plugins The team has little Kafka operations experience
Scale makes managed pricing very expensive Time to market matters more than per-unit cost
You already run stateful operators well You'd rather spend effort on the self-service layer

Either way, the platform work stays yours: topic provisioning, identities, quotas, schemas, golden paths, cost and support (lesson 17).

Try it: Strimzi on kind

  1. If you haven't yet, do lesson 5 first: it installs Strimzi and a 3-node cluster step by step, with real outputs.
  2. Follow the project Kafka as a platform service with Strimzi to install the operator and a small KRaft cluster.
  3. Change a broker setting in the Kafka resource and watch the operator roll the pods one at a time (kubectl get pods -n kafka -w).
  4. Add a KafkaTopic with 6 partitions and check its READY condition; then try changing it to 3 partitions and read the error condition.
  5. Delete a broker pod and watch it come back with the same PersistentVolumeClaim and broker ID.

Going deeper

  • Separate controller and broker node pools in production; controllers need little disk but must be stable and spread across zones.
  • Use topic and user operators in GitOps but block direct kafka-topics.sh --create (auto.create.topics.enable=false and ACLs), so Git stays the source of truth.
  • Plan cluster migrations (new version, new region, move to managed) with MirrorMaker 2 (lesson 16) rather than in-place heroics.

Recap

  • Kafka needs an operator on Kubernetes; Strimzi manages clusters, node pools, topics, users, Connect and mirroring as resources.
  • Advertised listeners must be reachable by clients; external listener types create per-broker access.
  • Use fast persistent storage, zones/racks, anti-affinity, and leave memory for the page cache.
  • The operator does safe rolling updates, certificate renewal and upgrades; Cruise Control rebalances partitions.
  • Managed services remove broker operations but not the platform work around Kafka.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.