c2sr bootcamp docs Help

Zookeeper Deployment Task

This tutorial provides a hands-on problem to solve. It is designed for students and junior DevOps engineers who are learning to translate service requirements into functional Kubernetes manifests. By completing this task, you will create a valid Kubernetes Deployment and an associated Service for Apache Zookeeper.

Following this guide will give you practical experience in configuring key aspects of a Kubernetes deployment and exposing it for network access, a critical skill for managing containerized applications.

In this tutorial, you will be tasked to:

  • Analyze a set of deployment and service requirements for Zookeeper.

  • Complete a skeleton YAML file for the Deployment.

  • Create a YAML file for the Service.

  • Prepare the manifests needed to deploy Zookeeper to the cluster.

Before you start

Make sure that:

  • You are SSHed into the k3smain node.

  • You have switched to the shared user account.

Part 1: Create the Zookeeper Deployment Manifest

Your first goal is to create a Kubernetes deployment file named zookeeper-deployment.yaml. This deployment will run the Zookeeper pods and must meet a specific set of operational requirements.

Deployment Requirements

The Zookeeper instance must be configured with the following specifications:

  1. Node Affinity: The pod must only be scheduled to run on the node named k3smain.

  2. Container Image: Use the latest bitnami/zookeeper image.

  3. Networking: The container must expose port 2181.

  4. Configuration: To simplify the setup, Zookeeper must be configured to allow anonymous logins.

  5. Storage: Zookeeper needs a path to store its data. For this simulation, it should use a non-persistent, ephemeral volume mounted at /bitnami/zookeeper.

  6. Resource Management: The container must be configured with specific resource requests and limits.

    • Requests: 256Mi of memory and 0.2 CPU.

    • Limits: 512Mi of memory and 0.5 CPU.

Skeleton File

To get you started, here is a skeleton zookeeper-deployment.yaml file. It is your job to fill in the missing values based on the requirements listed above.

# zookeeper-deployment.yaml --- apiVersion: apps/v1 kind: Deployment metadata: name: zookeeper labels: app: zookeeper spec: selector: matchLabels: app: zookeeper template: metadata: labels: app: zookeeper spec: nodeSelector: # Requirement 1: Add the correct node selector here kubernetes.io/hostname: <Your-Node-Name> containers: - name: zookeeper # Requirement 2: Specify the container image image: <Your-Image-Name> imagePullPolicy: Always ports: # Requirement 3: Define the container port - containerPort: <Your-Port> env: # Requirement 4: Set the environment variable for anonymous login - name: ALLOW_ANONYMOUS_LOGIN value: <"yes" or "no"> volumeMounts: # Requirement 5: Mount the data volume at the correct path - name: data mountPath: <Your-Mount-Path> resources: # Requirement 6: Set the resource requests and limits requests: memory: <Memory-Request> cpu: <CPU-Request> limits: memory: <Memory-Limit> cpu: <CPU-Limit> volumes: # Requirement 5: Define an ephemeral volume of type emptyDir - name: data # Add the correct volume type here

Part 2: Expose Zookeeper with a Service

Now that you have a Deployment, you need to create a stable network endpoint for it so other applications can find and communicate with the Zookeeper pods. Your second goal is to create a zookeeper-service.yaml file.

Service Requirements

The Service must:

  1. Have the name zookeeper-service.

  2. Forward traffic from its port 2181 to the targetPort 2181 on the pods.

  3. Use a selector to correctly identify the Zookeeper pods managed by your Deployment. This selector must match the labels on the pods.

Skeleton File for Service

Create a second file named zookeeper-service.yaml. Fill in the missing values in the skeleton below to provide the stable network endpoint that other applications (like Kafka) will use to communicate with Zookeeper.

# zookeeper-service.yaml --- apiVersion: v1 kind: Service metadata: # Requirement 1: Specify the service name name: <Your-Service-Name> labels: app: zookeeper spec: ports: # Requirement 2: Define the port and targetPort - port: <Service-Port> targetPort: <Pod-Port> # Requirement 3: Add the correct selector to target the Zookeeper pods selector: app: <Your-App-Label>

PArt 3: Deployment verification

Once you have created and completed both zookeeper-deployment.yaml and zookeeper-service.yaml, you need to apply them to the cluster.

kubectl apply -f zookeeper-deployment.yaml kubectl apply -f zookeeper-service.yaml

Verify the deployment: Check that the Zookeeper pod is running successfully.

kubectl get pods

Check zookeeper logs for error

kubectl logs <pod name>

Hint: The pod name is obtained from the previous command.

Solutions:

# zookeeper-deployment.yaml --- apiVersion: apps/v1 kind: Deployment metadata: name: zookeeper labels: app: zookeeper spec: selector: matchLabels: app: zookeeper template: metadata: labels: app: zookeeper spec: nodeSelector: kubernetes.io/hostname: k3smain containers: - name: zookeeper image: bitnami/zookeeper:latest imagePullPolicy: Always ports: - containerPort: 2181 env: - name: ALLOW_ANONYMOUS_LOGIN value: "yes" volumeMounts: - name: data mountPath: /bitnami/zookeeper resources: requests: memory: "256Mi" cpu: "0.2" limits: memory: "512Mi" cpu: "0.5" volumes: - name: data emptyDir: {}
apiVersion: v1 kind: Service metadata: name: zookeeper-service labels: app: zookeeper spec: ports: - port: 2181 targetPort: 2181 selector: app: zookeeper
Last modified: 22 June 2025