Bird
Raised Fist0
Kubernetesdevops~20 mins

Pod Disruption Budgets in Kubernetes - 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
🎖️
Pod Disruption Budget Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Pod Disruption Budget Purpose

What is the primary purpose of a Pod Disruption Budget (PDB) in Kubernetes?

ATo define resource limits for pods
BTo limit the number of pods that can be voluntarily disrupted at the same time
CTo scale pods up or down based on CPU usage
DTo automatically restart pods when they crash
Attempts:
2 left
💡 Hint

Think about how Kubernetes manages pod availability during maintenance or upgrades.

💻 Command Output
intermediate
2:00remaining
PDB Status After Node Drain

Given this Pod Disruption Budget YAML:

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: myapp-pdb
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: myapp

Assuming 3 pods labeled app=myapp are running, what will be the status of the PDB after draining a node hosting 2 pods?

ADisruptionsAllowed: 1, CurrentHealthy: 2, DesiredHealthy: 2
BDisruptionsAllowed: 2, CurrentHealthy: 3, DesiredHealthy: 2
CDisruptionsAllowed: 0, CurrentHealthy: 1, DesiredHealthy: 2
DDisruptionsAllowed: 0, CurrentHealthy: 3, DesiredHealthy: 2
Attempts:
2 left
💡 Hint

Consider how many pods remain healthy after removing 2 pods from 3 total.

Configuration
advanced
2:30remaining
Correct PDB YAML for MaxUnavailable

Which YAML snippet correctly defines a Pod Disruption Budget that allows at most 1 pod to be unavailable at any time for pods labeled app=web?

A
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-pdb
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app: web
B
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-pdb
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app: web
C
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-pdb
spec:
  maxUnavailable: "one"
  selector:
    matchLabels:
      app: web
D
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: web-pdb
spec:
  maxUnavailable: 2
  selector:
    matchLabels:
      app: web
Attempts:
2 left
💡 Hint

Check the correct field name and value type for limiting unavailable pods.

Troubleshoot
advanced
2:00remaining
Why is PDB Not Blocking Pod Eviction?

You created a Pod Disruption Budget with minAvailable: 3 for pods labeled app=api. There are 5 pods running. However, when you drain a node hosting 3 pods, Kubernetes allows eviction and the pods terminate. Why?

AThe pods are not managed by a controller, so PDB is ignored
BminAvailable must be less than total pods, so 3 is invalid here
CPDB only works for involuntary disruptions, not node drains
DThe PDB selector does not match the pods because labels differ
Attempts:
2 left
💡 Hint

Check if the PDB selector matches the pods exactly.

🔀 Workflow
expert
3:00remaining
Sequence to Safely Upgrade Nodes with PDB

Arrange the steps in the correct order to safely upgrade Kubernetes nodes without violating Pod Disruption Budgets for a deployment with 4 replicas and minAvailable: 3.

A1,2,3,4
B2,1,3,4
C1,3,2,4
D3,1,2,4
Attempts:
2 left
💡 Hint

Think about preventing new pods, safely evicting existing pods, upgrading, then reopening the node.

Practice

(1/5)
1. What is the main purpose of a Pod Disruption Budget in Kubernetes?
easy
A. To ensure a minimum number of pods stay available during planned disruptions
B. To automatically restart pods when they crash
C. To scale pods up or down based on CPU usage
D. To backup pod data before deletion

Solution

  1. Step 1: Understand Pod Disruption Budget purpose

    A Pod Disruption Budget (PDB) is designed to keep your app available during planned changes by limiting voluntary disruptions.
  2. Step 2: Match purpose to options

    To ensure a minimum number of pods stay available during planned disruptions correctly states that PDB ensures a minimum number of pods remain running during disruptions, unlike other options which describe unrelated features.
  3. Final Answer:

    To ensure a minimum number of pods stay available during planned disruptions -> Option A
  4. Quick Check:

    Pod Disruption Budget = availability during disruptions [OK]
Hint: PDB = minimum pods running during planned changes [OK]
Common Mistakes:
  • Confusing PDB with auto-scaling
  • Thinking PDB restarts crashed pods
  • Assuming PDB backs up pod data
2. Which of the following is the correct way to specify a Pod Disruption Budget that allows at most 1 pod disruption at a time for pods with label app=web?
easy
A. apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: pdb-web spec: maxUnavailable: 1 selector: matchLabels: app: web minReadySeconds: 10
B. apiVersion: v1 kind: PodDisruptionBudget metadata: name: pdb-web spec: minAvailable: 1 selector: matchLabels: app: web
C. apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: pdb-web spec: maxUnavailable: 1 selector: matchLabels: app: web strategy: RollingUpdate
D. apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: pdb-web spec: maxUnavailable: 1 selector: matchLabels: app: web

Solution

  1. Step 1: Check API version and kind

    The correct API version for PDB is policy/v1 and kind is PodDisruptionBudget.
  2. Step 2: Validate spec fields for maxUnavailable and selector

    apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: pdb-web spec: maxUnavailable: 1 selector: matchLabels: app: web correctly uses maxUnavailable: 1 and a selector matching label app: web. Other options either use wrong API version, extra unsupported fields, or wrong spec keys.
  3. Final Answer:

    apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: pdb-web spec: maxUnavailable: 1 selector: matchLabels: app: web -> Option D
  4. Quick Check:

    Correct API and maxUnavailable syntax = apiVersion: policy/v1 kind: PodDisruptionBudget metadata: name: pdb-web spec: maxUnavailable: 1 selector: matchLabels: app: web [OK]
Hint: Use policy/v1 and maxUnavailable with correct selector [OK]
Common Mistakes:
  • Using wrong API version like v1
  • Adding unsupported fields like strategy
  • Confusing minAvailable with maxUnavailable
3. Given this Pod Disruption Budget YAML snippet:
spec:
  minAvailable: 3
  selector:
    matchLabels:
      app: backend
If there are 5 pods with label app=backend, how many pods can be disrupted at once without violating the PDB?
medium
A. 3 pods
B. 2 pods
C. 5 pods
D. 0 pods

Solution

  1. Step 1: Understand minAvailable meaning

    minAvailable: 3 means at least 3 pods must stay running during disruptions.
  2. Step 2: Calculate allowed disruptions

    With 5 pods total, maximum disruptions allowed = 5 - 3 = 2 pods.
  3. Final Answer:

    2 pods -> Option B
  4. Quick Check:

    5 total - 3 minAvailable = 2 allowed disruptions [OK]
Hint: Allowed disruptions = total pods - minAvailable [OK]
Common Mistakes:
  • Confusing minAvailable with maxUnavailable
  • Assuming all pods can be disrupted
  • Ignoring total pod count
4. You applied this Pod Disruption Budget:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: pdb-db
spec:
  maxUnavailable: 2
  selector:
    matchLabels:
      app: database
But Kubernetes reports an error: "spec.maxUnavailable: Invalid value: "2": must be less than the number of pods selected by the label selector". What is the likely cause?
medium
A. There are fewer than 3 pods with label app=database
B. maxUnavailable must be a percentage, not a number
C. The selector label is incorrect syntax
D. PodDisruptionBudget requires minAvailable, not maxUnavailable

Solution

  1. Step 1: Understand maxUnavailable validation

    maxUnavailable must be less than the total number of pods matched by the selector.
  2. Step 2: Analyze error message meaning

    The error says "must be less than the number of pods" meaning the number of pods with label app=database is less than or equal to 2.
  3. Final Answer:

    There are fewer than 3 pods with label app=database -> Option A
  4. Quick Check:

    maxUnavailable < total pods = error if not [OK]
Hint: maxUnavailable must be less than pod count [OK]
Common Mistakes:
  • Using maxUnavailable as percentage incorrectly
  • Miswriting selector labels
  • Thinking minAvailable is mandatory
5. You have a deployment with 10 pods labeled app=frontend. You want to ensure that during voluntary disruptions, at least 80% of pods remain available. Which Pod Disruption Budget spec is correct?
hard
A. spec: minAvailable: 80 selector: matchLabels: app: frontend
B. spec: maxUnavailable: 8 selector: matchLabels: app: frontend
C. spec: maxUnavailable: 20% selector: matchLabels: app: frontend
D. spec: minAvailable: 20% selector: matchLabels: app: frontend

Solution

  1. Step 1: Understand percentage usage in PDB

    maxUnavailable and minAvailable can accept percentages. To keep 80% available, maxUnavailable should be 20%.
  2. Step 2: Evaluate options for correctness

    spec: minAvailable: 80 selector: matchLabels: app: frontend: minAvailable: 80 - absolute value exceeds total pods (10) - invalid.
    spec: maxUnavailable: 8 selector: matchLabels: app: frontend: maxUnavailable: 8 - allows 8 pods unavailable (only 20% available) - insufficient.
    spec: maxUnavailable: 20% selector: matchLabels: app: frontend: maxUnavailable: 20% - allows 20% (~2 pods) unavailable - ensures 80% available - correct.
    spec: minAvailable: 20% selector: matchLabels: app: frontend: minAvailable: 20% - ensures only at least 20% available - insufficient.
  3. Final Answer:

    spec: maxUnavailable: 20% selector: matchLabels: app: frontend -> Option C
  4. Quick Check:

    20% maxUnavailable = 80% pods available [OK]
Hint: Use maxUnavailable: 20% to keep 80% pods up [OK]
Common Mistakes:
  • Using minAvailable with percentage incorrectly
  • Confusing absolute numbers with percentages
  • Not matching selector labels properly