Production Apache Kafka on Kubernetes with Strimzi: GitOps, Topics, and TLS/SCRAM

DevOps tutorial - IT technology blog
DevOps tutorial - IT technology blog

Why Running Kafka on Kubernetes Breaks in Production

Your team needs an event streaming backbone for microservices. Someone grabs a Kubernetes YAML template, spins up three Kafka pods, and ships it. Staging looks green.

Then production traffic hits. A worker node drains for a routine kernel patch, and two Kafka brokers restart out of order. Producers hit their 30-second request.timeout.ms limit and start dropping events. Meanwhile, a developer needs a 12-partition topic, so an engineer execs into a pod and runs kafka-topics.sh by hand. Two weeks later, staging and production have drifted apart, TLS is still off because keystores felt painful, and 25 services are talking over plaintext.

Manual Kafka ops on Kubernetes fall apart fast once you leave demo scale. Getting stateful streaming right means automating broker lifecycles, topics, and security before a 3:00 AM page forces your hand.

What Actually Goes Wrong Under the Hood

Naive Kubernetes deployments clash with how Apache Kafka actually works:

  • Stateful lifecycle complexity: Stateless APIs can restart in any order. Kafka brokers hold partition replicas, leader elections, and cluster metadata. Restarting pods without checking under-replicated partitions can stall writes or cause data loss.
  • Imperative configuration drift: Running CLI commands inside a container leaves zero Git history. Nobody knows who changed retention.ms or bumped partitions last Tuesday.
  • Security friction: Rotating CA certificates every 90 days and managing SASL SCRAM-SHA-512 credentials across 30 microservices by hand is error-prone. Teams push security to “next sprint” until an audit or incident hits.

Kubernetes reconciles desired state well, but built-in resources like StatefulSet and ConfigMap know nothing about Kafka’s protocol, partition leadership, or broker configs.

Comparing Ways to Run Kafka on Kubernetes

Three patterns dominate self-hosted Kafka on Kubernetes, and they trade off control against operational toil:

  • Raw StatefulSets and ConfigMaps: You write every manifest and entrypoint script yourself. Rolling upgrades, cert rotation, and topic scripts fall on your team. Skip this unless you run a dedicated Kafka platform group.
  • Generic Helm Charts: Charts get a cluster up in five minutes, but they mostly template day-one install. Day-two tasks—safe broker scaling, TLS rotation, or topics as code—still push you back to custom scripts.
  • Strimzi Operator: Strimzi extends Kubernetes with Custom Resource Definitions (CRDs) like Kafka, KafkaTopic, and KafkaUser. Its operators watch those CRDs and reconcile the live cluster automatically, which fits GitOps natively.

Managed services like Amazon MSK or Confluent Cloud make sense if you want zero cluster ops. When cost, data residency, or latency keep you inside your own Kubernetes clusters, Strimzi is the standard choice.

Step-by-Step: Production Kafka with Strimzi and GitOps

Here is how to deploy a 3-node Kafka cluster in KRaft mode (no ZooKeeper), wire up declarative topics, enforce TLS with SCRAM-SHA-512, and sync everything through Git.

Step 1: Install the Strimzi Cluster Operator

Create a dedicated kafka namespace and install the operator. In production, commit the Strimzi Helm chart or release YAML to your GitOps repo; for a quick test, apply the official manifest directly:

kubectl create namespace kafka
kubectl create -f 'https://strimzi.io/install/latest?namespace=kafka' -n kafka

# Wait for the operator pod to report 1/1 Running
kubectl get pods -n kafka -w

Confirm strimzi-cluster-operator reaches 1/1 Running before creating cluster resources.

Step 2: Define a Production Kafka Cluster in KRaft Mode

Save the manifest below as kafka-cluster.yaml. It pairs a KafkaNodePool (required for KRaft) with a Kafka resource, turns on TLS on port 9093 with SCRAM-SHA-512, and allocates 100Gi of persistent storage per node:

apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaNodePool
metadata:
  name: dual-role
  namespace: kafka
  labels:
    strimzi.io/cluster: prod-kafka
spec:
  replicas: 3
  roles:
    - controller
    - broker
  storage:
    type: jbod
    volumes:
      - id: 0
        type: persistent-claim
        size: 100Gi
        deleteClaim: false
  resources:
    requests:
      memory: 4Gi
      cpu: "1"
    limits:
      memory: 6Gi
      cpu: "2"
---
apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
  name: prod-kafka
  namespace: kafka
  annotations:
    strimzi.io/node-pools: enabled
    strimzi.io/kraft: enabled
spec:
  kafka:
    version: 3.8.0
    metadataVersion: 3.8-IV0
    listeners:
      - name: tls
        port: 9093
        type: internal
        tls: true
        authentication:
          type: scram-sha-512
    authorization:
      type: simple
    config:
      offsets.topic.replication.factor: 3
      transaction.state.log.replication.factor: 3
      transaction.state.log.min.isr: 2
      default.replication.factor: 3
      min.insync.replicas: 2
  entityOperator:
    topicOperator: {}
    userOperator: {}

Two settings do heavy lifting here. Setting deleteClaim: false keeps your 100Gi volumes intact if someone deletes the cluster resource. Pairing min.insync.replicas: 2 with a replication factor of 3 lets you lose one broker without dropping writes when producers use acks=all. For multi-zone resilience, also add podAntiAffinity under KafkaNodePool.spec.template.pod.affinity so Kubernetes spreads brokers across nodes and availability zones.

Step 3: Manage Topics Declaratively

Stop exec-ing into pods to run CLI scripts. Define every topic as a KafkaTopic manifest in Git instead, starting with orders-topic.yaml:

apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaTopic
metadata:
  name: orders.events
  namespace: kafka
  labels:
    strimzi.io/cluster: prod-kafka
spec:
  partitions: 6
  replicas: 3
  config:
    retention.ms: 604800000
    cleanup.policy: delete
    min.insync.replicas: 2

Applying this file tells the Topic Operator to create orders.events with 6 partitions and a 7-day retention window (604800000 ms). Need to double consumer concurrency later? Bump partitions from 6 to 12 in a pull request, and Strimzi expands the topic online without downtime.

Step 4: Secure Clients with TLS and SCRAM-SHA-512

Every microservice should authenticate with least-privilege ACLs. Save this KafkaUser manifest as orders-service-user.yaml:

apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaUser
metadata:
  name: orders-service
  namespace: kafka
  labels:
    strimzi.io/cluster: prod-kafka
spec:
  authentication:
    type: scram-sha-512
  authorization:
    type: simple
    acls:
      - resource:
          type: topic
          name: orders.events
          patternType: literal
        operations:
          - Read
          - Write
          - Describe

Strimzi responds by creating a Kubernetes Secret named orders-service with the SCRAM credentials (password and sasl.jaas.config). It also maintains the cluster CA certificate in prod-kafka-cluster-ca-cert (ca.crt). Your app mounts both secrets—no manual keytool commands or hardcoded passwords. Note that if orders-service also consumes events, add a second ACL granting Read on its consumer group resource.

Step 5: Wire Everything into a GitOps Workflow

Store kafka-cluster.yaml, your KafkaTopic manifests, and your KafkaUser files under a single path in Git, such as clusters/prod/kafka/. Point Argo CD or Flux at that directory to reconcile changes automatically.

# Verify all Strimzi resources are synced and ready
kubectl get kafka,kafkanodepool,kafkatopic,kafkauser -n kafka

# Inspect the generated SCRAM secret
kubectl get secret orders-service -n kafka -o yaml

Every cluster change now follows a predictable pull request loop:

  1. A developer opens a PR adding a KafkaTopic or requesting ACLs in a KafkaUser manifest.
  2. A reviewer checks partition counts, retention limits, and ACL scope directly in the diff.
  3. After merge, Argo CD or Flux applies the YAML, and Strimzi reconciles the live cluster within seconds.

With Strimzi handling Kafka’s internals and GitOps controlling every manifest, configuration drift disappears. TLS and SCRAM-SHA-512 stay on by default, and cluster changes become boring, auditable commits.

Share: