Bird
Raised Fist0
Microservicessystem_design~20 mins

Pods and deployments for services in Microservices - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Pods and Deployments Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary role of a Pod in Kubernetes?
Imagine you have a small team working together in a room to complete a task. In Kubernetes, a Pod is like that team. What is the main purpose of a Pod?
AIt stores persistent data for containers to use.
BIt manages the deployment and scaling of containers automatically.
CIt acts as a load balancer to distribute traffic among services.
DIt groups one or more containers that share storage and network resources.
Attempts:
2 left
💡 Hint
Think about what runs inside a Pod and what resources they share.
Architecture
intermediate
2:00remaining
How does a Deployment help manage Pods in Kubernetes?
Think of a Deployment as a manager who ensures the right number of workers (Pods) are always available. What is the main function of a Deployment?
AIt ensures a specified number of Pods are running and updates them smoothly.
BIt provides persistent storage to Pods for data retention.
CIt schedules Pods to specific nodes based on resource availability.
DIt routes external traffic directly to individual Pods.
Attempts:
2 left
💡 Hint
Consider how you keep a team size constant and update their tasks without disruption.
scaling
advanced
2:00remaining
What happens when you scale a Deployment from 3 to 6 replicas?
You have a Deployment running 3 Pods. You decide to scale it to 6. What is the expected behavior in Kubernetes?
AKubernetes merges the 3 Pods into 6 containers within the same Pods.
BKubernetes replaces the existing 3 Pods with 6 new Pods on the same nodes.
CKubernetes creates 3 additional Pods to reach 6 total, distributing them across nodes.
DKubernetes pauses all Pods and restarts 6 Pods sequentially.
Attempts:
2 left
💡 Hint
Think about how Kubernetes adds capacity without stopping existing Pods.
tradeoff
advanced
2:00remaining
What is a tradeoff when using a single Pod with multiple containers versus multiple Pods with single containers?
Consider running multiple containers inside one Pod versus running each container in its own Pod. What is a key tradeoff?
ASingle Pod containers cannot communicate internally; multiple Pods communicate via shared memory.
BSingle Pod containers share resources closely but reduce isolation; multiple Pods increase isolation but add network overhead.
CSingle Pod containers require separate IPs; multiple Pods share the same IP address.
DSingle Pod containers have better network isolation; multiple Pods share storage more efficiently.
Attempts:
2 left
💡 Hint
Think about resource sharing and security boundaries.
estimation
expert
3:00remaining
Estimate the number of Pods needed for a service expecting 10,000 requests per second with each Pod handling 500 requests per second.
You have a microservice deployed with Pods that can each handle 500 requests per second. To handle 10,000 requests per second reliably, how many Pods should you deploy?
A20 Pods
B15 Pods
C25 Pods
D10 Pods
Attempts:
2 left
💡 Hint
Divide total requests by capacity per Pod and consider no overloading.

Practice

(1/5)
1. What is the main role of a Pod in a microservices architecture?
easy
A. To manage updates and scaling of containers
B. To run one or more containers together as a single unit
C. To route network traffic between services
D. To store persistent data for containers

Solution

  1. Step 1: Understand what a Pod is

    A Pod is the smallest deployable unit in Kubernetes that runs one or more containers together.
  2. Step 2: Differentiate Pod from other components

    Deployments manage Pods, Services route traffic, and persistent storage is handled separately.
  3. Final Answer:

    To run one or more containers together as a single unit -> Option B
  4. Quick Check:

    Pod = container unit [OK]
Hint: Pods run containers; deployments manage pods [OK]
Common Mistakes:
  • Confusing Pods with Deployments
  • Thinking Pods handle networking
  • Assuming Pods store data
2. Which of the following is the correct YAML snippet to define a Deployment that runs 3 replicas of a Pod?
easy
A. kind: Pod\nreplicas: 3\nmetadata:\n name: my-pod
B. replicas: 3\nkind: Service\nmetadata:\n name: my-service
C. replicas: 3\nkind: Deployment\nmetadata:\n name: my-deployment
D. kind: Deployment\nmetadata:\n name: my-deployment\nreplicas: three

Solution

  1. Step 1: Identify correct kind and replicas field

    Deployment kind is correct and replicas should be a number, here 3.
  2. Step 2: Check metadata and syntax

    Metadata name is valid; 'replicas: three' is invalid because replicas must be numeric.
  3. Final Answer:

    replicas: 3\nkind: Deployment\nmetadata:\n name: my-deployment -> Option C
  4. Quick Check:

    Deployment with numeric replicas = correct YAML [OK]
Hint: Deployments use 'kind: Deployment' and numeric replicas [OK]
Common Mistakes:
  • Using 'kind: Pod' instead of Deployment
  • Setting replicas as a word instead of number
  • Confusing Service with Deployment
3. Given this Deployment YAML snippet, how many Pods will be running after applying it?
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 4
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web-container
        image: nginx
medium
A. 4 Pods
B. 0 Pods until manually started
C. 1 Pod
D. Depends on the number of nodes

Solution

  1. Step 1: Read replicas count in Deployment spec

    The replicas field is set to 4, meaning Kubernetes will maintain 4 Pods.
  2. Step 2: Understand Deployment behavior

    Deployment automatically creates and manages the specified number of Pods.
  3. Final Answer:

    4 Pods -> Option A
  4. Quick Check:

    replicas = 4 Pods running [OK]
Hint: replicas number = Pods count after deployment [OK]
Common Mistakes:
  • Assuming only 1 Pod runs by default
  • Thinking Pods need manual start
  • Confusing nodes with Pod count
4. You applied a Deployment YAML but notice no Pods are running. Which is the most likely cause?
apiVersion: apps/v1 kind: Deployment metadata: name: api-server spec: replicas: 3 selector: matchLabels: app: api template: metadata: labels: app: backend spec: containers: - name: api-container image: myapi:latest
medium
A. The Deployment kind is incorrect
B. The replicas count is too high for the cluster
C. The container image name is invalid
D. The selector labels do not match the Pod template labels

Solution

  1. Step 1: Compare selector and template labels

    The selector uses label 'app: api' but the Pod template labels 'app: backend' which do not match.
  2. Step 2: Understand label matching importance

    Deployment uses selector to manage Pods; mismatch means no Pods are controlled or created.
  3. Final Answer:

    The selector labels do not match the Pod template labels -> Option D
  4. Quick Check:

    Selector labels must match Pod labels [OK]
Hint: Selector and Pod labels must match exactly [OK]
Common Mistakes:
  • Ignoring label mismatch
  • Assuming image name causes no Pods
  • Thinking replicas count blocks Pod creation
5. You want to update a microservice with zero downtime using Kubernetes. Which approach best uses Pods and Deployments to achieve this?
hard
A. Update the Deployment with a new image version; Kubernetes creates new Pods and gradually replaces old ones
B. Delete all old Pods manually and then create new Pods with the updated image
C. Scale down the Deployment to zero replicas, then scale up with the new image
D. Create a new Deployment with the updated image and delete the old Deployment immediately

Solution

  1. Step 1: Understand Deployment update strategy

    Deployments support rolling updates that create new Pods and remove old Pods gradually.
  2. Step 2: Compare options for zero downtime

    Manual deletion or scaling down causes downtime; creating new Deployment causes conflicts.
  3. Final Answer:

    Update the Deployment with a new image version; Kubernetes creates new Pods and gradually replaces old ones -> Option A
  4. Quick Check:

    Rolling update = zero downtime update [OK]
Hint: Use Deployment rolling updates for zero downtime [OK]
Common Mistakes:
  • Deleting Pods manually causing downtime
  • Scaling to zero causes service interruption
  • Creating new Deployment causes conflicts