Bird
Raised Fist0
Kubernetesdevops~10 mins

Pod stuck in Pending state in Kubernetes - Interactive Code Practice

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the command to check the status of pods in the default namespace.

Kubernetes
kubectl get pods --namespace=[1]
Drag options to blanks, or click blank then click option'
Akube-system
Ball
Cdefault
Dpending
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'all' instead of a namespace
Using 'pending' which is a pod status, not a namespace
2fill in blank
medium

Complete the command to describe a pod named 'myapp-pod' to find why it is Pending.

Kubernetes
kubectl describe pod [1]
Drag options to blanks, or click blank then click option'
Apod-myapp
Bpending-pod
Cmy-pod-app
Dmyapp-pod
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect pod names
Swapping words in the pod name
3fill in blank
hard

Fix the error in this YAML snippet to request CPU resources correctly for a pod.

Kubernetes
resources:
  requests:
    cpu: [1]
Drag options to blanks, or click blank then click option'
A100m
B100
C0.1
D1000m
Attempts:
3 left
💡 Hint
Common Mistakes
Using plain numbers without units
Using decimal numbers without 'm'
4fill in blank
hard

Fill both blanks to create a node selector that schedules pods only on nodes labeled with environment=production.

Kubernetes
nodeSelector:
  [1]: [2]
Drag options to blanks, or click blank then click option'
Aenvironment
Bproduction
Cstaging
Dzone
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping key and value
Using wrong label keys or values
5fill in blank
hard

Fill all three blanks to create a pod affinity rule that prefers nodes in the 'us-east' zone with label 'zone=us-east'.

Kubernetes
affinity:
  podAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: [1]
      podAffinityTerm:
        labelSelector:
          matchExpressions:
          - key: [2]
            operator: In
            values:
            - [3]
Drag options to blanks, or click blank then click option'
A100
Bzone
Cus-east
Denvironment
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong weight values
Using incorrect label keys or values

Practice

(1/5)
1. What does it usually mean when a Kubernetes Pod is stuck in the Pending state?
easy
A. Kubernetes cannot find a suitable node to run the Pod.
B. The Pod has completed its task and is terminating.
C. The Pod is running but not responding to requests.
D. The Pod has been deleted from the cluster.

Solution

  1. Step 1: Understand Pod lifecycle states

    The Pending state means the Pod is created but not yet scheduled to a node.
  2. Step 2: Identify reason for Pending

    Pending usually happens when no node meets the Pod's resource or scheduling requirements.
  3. Final Answer:

    Kubernetes cannot find a suitable node to run the Pod. -> Option A
  4. Quick Check:

    Pending = No suitable node found [OK]
Hint: Pending means no node fits Pod's needs [OK]
Common Mistakes:
  • Confusing Pending with Running state
  • Thinking Pending means Pod is deleted
  • Assuming Pending means Pod is ready
2. Which kubectl command helps you see detailed reasons why a Pod is stuck in Pending state?
easy
A. kubectl get pods
B. kubectl describe pod
C. kubectl logs
D. kubectl delete pod

Solution

  1. Step 1: Identify command to get detailed Pod info

    kubectl describe pod shows events and status details for the Pod.
  2. Step 2: Confirm command usage

    This command reveals scheduling failures or resource issues causing Pending.
  3. Final Answer:

    kubectl describe pod <pod-name> -> Option B
  4. Quick Check:

    Describe Pod = Detailed status [OK]
Hint: Use describe to see Pod events and reasons [OK]
Common Mistakes:
  • Using get pods only shows summary, not reasons
  • Using logs shows container logs, not scheduling info
  • Deleting Pod does not show status
3. Given this kubectl describe pod mypod output snippet:
Events:
  Type     Reason            Age   From               Message
  ----     ------            ----  ----               -------
  Warning  FailedScheduling  2m    default-scheduler  0/3 nodes are available: 3 Insufficient cpu.

What is the main reason the Pod is stuck in Pending?
medium
A. There is no node with enough CPU available.
B. The Pod image is not found.
C. The Pod has a syntax error in its YAML.
D. The Pod is already running on another node.

Solution

  1. Step 1: Analyze the event message

    The message says "0/3 nodes are available: 3 Insufficient cpu." meaning no node has enough CPU resources.
  2. Step 2: Understand impact on scheduling

    Without enough CPU, the scheduler cannot place the Pod, so it stays Pending.
  3. Final Answer:

    There is no node with enough CPU available. -> Option A
  4. Quick Check:

    Insufficient CPU = Pod Pending [OK]
Hint: Look for 'Insufficient cpu' in describe events [OK]
Common Mistakes:
  • Confusing image errors with scheduling errors
  • Assuming YAML syntax causes Pending
  • Thinking Pod runs on multiple nodes
4. You see a Pod stuck in Pending state. You check kubectl describe pod and find the message: 0/2 nodes are available: 2 node(s) didn't match Pod's node selector.
What should you do to fix this?
medium
A. Delete the Pod and recreate it without changes.
B. Increase the Pod's CPU requests to match node capacity.
C. Remove or correct the Pod's nodeSelector labels to match available nodes.
D. Restart the Kubernetes cluster.

Solution

  1. Step 1: Understand nodeSelector impact

    The Pod's nodeSelector restricts scheduling to nodes with matching labels.
  2. Step 2: Fix nodeSelector to match nodes

    Adjust or remove nodeSelector so nodes in cluster match Pod requirements.
  3. Final Answer:

    Remove or correct the Pod's nodeSelector labels to match available nodes. -> Option C
  4. Quick Check:

    nodeSelector mismatch = fix labels [OK]
Hint: Check and fix nodeSelector labels to match nodes [OK]
Common Mistakes:
  • Increasing CPU requests worsens scheduling
  • Deleting Pod without fixing selector won't help
  • Restarting cluster is unnecessary
5. A Pod requests 4 CPUs but all nodes in your cluster have only 2 CPUs each. The Pod stays Pending. Which is the best way to fix this?
hard
A. Change the Pod's image to a smaller size.
B. Reduce the Pod's CPU request to 2 or less.
C. Remove resource requests from the Pod spec.
D. Add a node with at least 4 CPUs to the cluster.

Solution

  1. Step 1: Understand resource requests vs node capacity

    The Pod requests 4 CPUs but nodes have only 2 CPUs, so no node can run it.
  2. Step 2: Choose solution to meet resource needs

    Adding a node with enough CPUs allows the Pod to be scheduled properly.
  3. Final Answer:

    Add a node with at least 4 CPUs to the cluster. -> Option D
  4. Quick Check:

    Pod CPU request > node CPU = add bigger node [OK]
Hint: Match Pod CPU request with node CPU capacity [OK]
Common Mistakes:
  • Reducing CPU request may not be possible or desired
  • Removing requests can cause unstable scheduling
  • Changing image size does not affect CPU requests