Bird
Raised Fist0
Kafkadevops~10 mins

Kafka on Kubernetes (Strimzi) - Step-by-Step Execution

Choose your learning style10 modes available
Process Flow - Kafka on Kubernetes (Strimzi)
Create Kubernetes Namespace
↓
Apply Strimzi Operator YAML
↓
Operator Installs Kafka Cluster CRDs
↓
Create Kafka Cluster Custom Resource
↓
Operator Deploys Kafka Pods & Services
↓
Kafka Cluster Runs inside Kubernetes
↓
Clients Connect to Kafka via Services
This flow shows how Strimzi operator manages Kafka on Kubernetes: install operator, create Kafka resource, operator deploys Kafka pods, then clients connect.
Execution Sample
Kafka
kubectl create namespace kafka
kubectl apply -f strimzi-cluster-operator.yaml -n kafka
kubectl apply -f kafka-cluster.yaml -n kafka
kubectl get pods -n kafka
Commands to create namespace, install Strimzi operator, deploy Kafka cluster, and check Kafka pods running.
Process Table
StepCommandActionResult/Output
1kubectl create namespace kafkaCreate namespace 'kafka'namespace/kafka created
2kubectl apply -f strimzi-cluster-operator.yaml -n kafkaInstall Strimzi operatordeployment.apps/strimzi-cluster-operator created
3Operator installs Kafka CRDsCustom Resource Definitions addedkafkas.kafka.strimzi.io CRD created
4kubectl apply -f kafka-cluster.yaml -n kafkaCreate Kafka cluster resourcekafka.kafka.strimzi.io/my-cluster created
5Operator deploys Kafka podsKafka pods startingpod/my-cluster-kafka-0 Running pod/my-cluster-kafka-1 Running pod/my-cluster-kafka-2 Running
6kubectl get pods -n kafkaCheck Kafka pods statusNAME READY STATUS RESTARTS AGE my-cluster-kafka-0 1/1 Running 0 2m my-cluster-kafka-1 1/1 Running 0 2m my-cluster-kafka-2 1/1 Running 0 2m
7Kafka cluster readyKafka cluster is runningKafka cluster pods are all Running and Ready
💡 Kafka pods are Running and Ready, cluster is ready for clients
Status Tracker
ResourceInitial StateAfter Step 2After Step 4After Step 5Final State
Namespace 'kafka'Not presentCreatedCreatedCreatedCreated
Strimzi OperatorNot installedInstalledInstalledInstalledInstalled
Kafka CRDsNot presentInstalledInstalledInstalledInstalled
Kafka Cluster ResourceNot presentNot presentCreatedCreatedCreated
Kafka PodsNot presentNot presentNot presentStartingRunning
Key Moments - 3 Insights
Why do we need to create a namespace before installing Strimzi?
The namespace isolates Kafka resources. Step 1 creates it so Strimzi operator and Kafka pods run inside it, as shown in execution_table row 1.
What happens if we apply the Kafka cluster resource before installing Strimzi operator?
The Kafka CRDs won't exist yet, so Kubernetes rejects the Kafka cluster resource. Step 3 shows CRDs must be installed first.
Why do we check pod status after deploying Kafka cluster?
To confirm Kafka pods are running and ready for use. Execution_table rows 5 and 6 show pods transitioning to Running state.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3. What does the operator install?
AKafka Custom Resource Definitions (CRDs)
BKafka client tools
CKafka pods
DKubernetes namespace
💡 Hint
Check the 'Action' and 'Result/Output' columns at step 3 in execution_table.
At which step do Kafka pods start running?
AStep 2
BStep 4
CStep 5
DStep 7
💡 Hint
Look at the 'Action' and 'Result/Output' columns for pod status in execution_table.
If the namespace 'kafka' was not created, what would happen at step 2?
AOperator installs successfully in default namespace
Bkubectl apply fails because namespace does not exist
CKafka cluster deploys anyway
DPods start running in default namespace
💡 Hint
Refer to variable_tracker for namespace state and execution_table step 1 and 2.
Concept Snapshot
Kafka on Kubernetes with Strimzi:
- Create a Kubernetes namespace for Kafka
- Install Strimzi operator YAML in that namespace
- Operator adds Kafka CRDs to Kubernetes
- Apply Kafka cluster custom resource YAML
- Operator deploys Kafka pods and services
- Check pods are Running before using Kafka
- Clients connect via Kubernetes services
Full Transcript
This visual execution shows how to run Kafka on Kubernetes using Strimzi operator. First, create a namespace called 'kafka' to isolate resources. Then apply the Strimzi operator YAML in that namespace. The operator installs Kafka Custom Resource Definitions (CRDs) into Kubernetes. Next, apply a Kafka cluster custom resource YAML to request a Kafka cluster. The operator sees this and deploys Kafka pods and services inside the namespace. Finally, check the pods are running and ready. Once ready, clients can connect to Kafka through Kubernetes services. This step-by-step flow helps beginners see how Kubernetes and Strimzi work together to run Kafka.

Practice

(1/5)
1. What is the main purpose of Strimzi when running Kafka on Kubernetes?
easy
A. To simplify and automate Kafka cluster management on Kubernetes
B. To replace Kubernetes with a new container orchestration system
C. To provide a graphical user interface for Kafka topics
D. To convert Kafka messages into SQL queries automatically

Solution

  1. Step 1: Understand Strimzi's role

    Strimzi is designed to help run Kafka on Kubernetes by managing Kafka clusters easily.
  2. Step 2: Identify the correct purpose

    It automates pod management, storage, and recovery, simplifying Kafka operations on Kubernetes.
  3. Final Answer:

    To simplify and automate Kafka cluster management on Kubernetes -> Option A
  4. Quick Check:

    Strimzi = Kafka automation on Kubernetes [OK]
Hint: Strimzi automates Kafka on Kubernetes, not replaces or adds UI [OK]
Common Mistakes:
  • Thinking Strimzi replaces Kubernetes
  • Confusing Strimzi with Kafka UI tools
  • Assuming Strimzi converts Kafka messages to SQL
2. Which of the following is the correct command to apply a Kafka cluster YAML file named kafka-cluster.yaml using Strimzi on Kubernetes?
easy
A. kubectl run kafka-cluster.yaml
B. strimzi create kafka-cluster.yaml
C. kubectl apply -f kafka-cluster.yaml
D. kafka apply kafka-cluster.yaml

Solution

  1. Step 1: Recall how Kubernetes applies YAML files

    Kubernetes uses kubectl apply -f filename.yaml to create or update resources.
  2. Step 2: Match the command to Strimzi usage

    Strimzi uses Kubernetes resources, so applying the Kafka cluster YAML is done with kubectl apply -f.
  3. Final Answer:

    kubectl apply -f kafka-cluster.yaml -> Option C
  4. Quick Check:

    Apply YAML with kubectl apply -f [OK]
Hint: Use kubectl apply -f for YAML files on Kubernetes [OK]
Common Mistakes:
  • Using non-existent 'strimzi create' command
  • Confusing kubectl run with apply
  • Trying to use kafka CLI for Kubernetes YAML
3. Given the following YAML snippet for a Kafka cluster managed by Strimzi:
apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
  name: my-cluster
spec:
  kafka:
    replicas: 3
    storage:
      type: ephemeral
  zookeeper:
    replicas: 3
    storage:
      type: ephemeral

What will be the number of Kafka broker pods created in the Kubernetes cluster?
medium
A. 3
B. 0
C. 6
D. 1

Solution

  1. Step 1: Identify Kafka replicas in YAML

    The replicas field under kafka is set to 3, meaning 3 Kafka broker pods.
  2. Step 2: Understand pod creation

    Strimzi creates one pod per replica, so 3 Kafka broker pods will be created.
  3. Final Answer:

    3 -> Option A
  4. Quick Check:

    Kafka replicas = 3 pods [OK]
Hint: Kafka replicas number = Kafka pods count [OK]
Common Mistakes:
  • Adding Kafka and Zookeeper replicas together
  • Confusing ephemeral storage with pod count
  • Assuming default pod count if replicas missing
4. You applied a Kafka cluster YAML with 3 replicas, but only 1 Kafka pod is running. Which of the following is the most likely cause?
medium
A. Kafka storage type is set to ephemeral
B. The YAML file has replicas: 1 under Kafka section
C. Zookeeper replicas are set to 1
D. Strimzi operator is not installed or running

Solution

  1. Step 1: Check Kafka replicas in YAML

    If YAML specifies 3 replicas, pod count should be 3, so replicas: 1 is unlikely.
  2. Step 2: Consider Strimzi operator role

    Strimzi operator manages Kafka pods. If it is missing or not running, pods won't be created properly.
  3. Final Answer:

    Strimzi operator is not installed or running -> Option D
  4. Quick Check:

    Operator missing = pods not managed [OK]
Hint: Check Strimzi operator status if pods don't match replicas [OK]
Common Mistakes:
  • Blaming Zookeeper replicas for Kafka pod count
  • Thinking ephemeral storage stops pod creation
  • Assuming YAML replicas value is always correct
5. You want to update your Kafka cluster managed by Strimzi to use persistent storage instead of ephemeral. Which YAML snippet correctly changes the Kafka storage to persistent with 10Gi volume size?
hard
A. storage: type: persistent-claim size: 10Gi
B. storage: type: persistent-claim volumeClaimTemplate: spec: resources: requests: storage: 10Gi
C. storage: type: persistent size: 10Gi
D. storage: persistentVolume: size: 10Gi

Solution

  1. Step 1: Understand Strimzi persistent storage syntax

    Strimzi uses persistent-claim type with a volumeClaimTemplate to define PVC size.
  2. Step 2: Identify correct YAML structure

    storage: type: persistent-claim volumeClaimTemplate: spec: resources: requests: storage: 10Gi correctly uses volumeClaimTemplate.spec.resources.requests.storage: 10Gi to request 10Gi persistent volume.
  3. Final Answer:

    storage: type: persistent-claim volumeClaimTemplate: spec: resources: requests: storage: 10Gi -> Option B
  4. Quick Check:

    Persistent storage needs volumeClaimTemplate with size [OK]
Hint: Use volumeClaimTemplate for persistent storage size in Strimzi [OK]
Common Mistakes:
  • Using 'size' directly under storage without volumeClaimTemplate
  • Using wrong storage type like 'persistent'
  • Confusing persistentVolume with persistent-claim
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard