SKILL.md--- name: deploying-kafka-k8s description: | Deploys Apache Kafka on Kubernetes using the Strimzi operator with KRaft mode. Use when setting up Kafka for event-driven microservices, message queuing, or pub/sub patterns. Covers operator installation, cluster creation, topic management, and producer/consumer testing. NOT when using managed Kafka (Confluent Cloud, MSK) or local development without K8s. --- # Deploying Kafka on Kubernetes Deploy production-ready Apache Kafka clusters using Strimzi operator (v0.49.1+) with KRaft mode. ## Quick Start ```bash # 1. Create namespace kubectl create namespace kafka # 2. Install Strimzi operator kubectl create -f 'https://strimzi.io/install/latest?namespace=kafka' -n kafka # 3. Wait for operator kubectl wait deployment/strimzi-cluster-operator --for=condition=Available -n kafka --timeout=300s # 4. Deploy Kafka cluster kubectl apply -f https://strimzi.io/examples/latest/kafka/kraft/kafka-single-node.yaml -n kafka # 5. Wait for ready kubectl wait kafka/my-cluster --for=condition=Ready --timeout=300s -n kafka ``` ## Strimzi Operator Installation ### Standard Install (Cluster-wide) ```bash kubectl create namespace kafka kubectl create -f 'https://strimzi.io/install/latest?namespace=kafka' -n kafka kubectl get pods -n kafka -w ``` ### Namespace-scoped Install ```bash # Download and modify for single namespace curl -L https://strimzi.io/install/latest?namespace=kafka > strimzi-install.yaml # Edit RoleBindings and ClusterRoles as needed kubectl apply -f strimzi-install.yaml -n kafka ``` ## Kafka Cluster Configurations ### Single Node (Development) ```yaml apiVersion: kafka.strimzi.io/v1beta2 kind: Kafka metadata: name: my-cluster namespace: kafka spec: kafka: version: 3.9.0 replicas: 1 listeners: - name: plain port: 9092 type: internal tls: false - name: tls port: 9093 type: internal tls: true config: offsets.topic.replication.factor: 1 transaction.state.log.replication.factor: 1 transaction.state.log.min.isr: 1 default.replication.factor: 1 min.insync.replicas: 1 storage: type: ephemeral entityOperator: topicOperator: {} userOperator: {} ``` ### Production Cluster (3 Nodes + KRaft) ```yaml apiVersion: kafka.strimzi.io/v1beta2 kind: Kafka metadata: name: kafka-production namespace: kafka spec: kafka: version: 3.9.0 replicas: 3 listeners: - name: plain port: 9092 type: internal tls: false - name: tls port: 9093 type: internal tls: true - name: external port: 9094 type: nodeport tls: false 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 inter.broker.protocol.version: "3.9" storage: type: jbod volumes: - id: 0 type: persistent-claim size: 100Gi deleteClaim: false resources: requests: memory: 2Gi cpu: "500m" limits: memory: 4Gi cpu: "2" entityOperator: topicOperator: {} userOperator: {} ``` ## Top