Bird
Raised Fist0
Kubernetesdevops~5 mins

Pod stuck in Pending state in Kubernetes - Commands & Configuration

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
Introduction
Sometimes, a Kubernetes pod does not start running and stays in Pending state. This means Kubernetes is trying to find a place to run the pod but cannot. This problem stops your app from working.
When you deploy a new pod and it never starts running.
When your pod is waiting but not showing any errors.
When you want to check why Kubernetes cannot schedule your pod.
When your cluster resources are full and new pods cannot start.
When you suspect configuration issues like missing node selectors or insufficient resources.
Commands
Check the status of all pods in the current namespace to see which pods are Pending.
Terminal
kubectl get pods
Expected OutputExpected
NAME READY STATUS RESTARTS AGE example-pod 0/1 Pending 0 2m
Get detailed information about the pod, including events that explain why it is Pending.
Terminal
kubectl describe pod example-pod
Expected OutputExpected
Name: example-pod Namespace: default Status: Pending ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 1m default-scheduler 0/3 nodes are available: 3 Insufficient cpu.
Check the status and resources of all nodes to see if they can run new pods.
Terminal
kubectl get nodes
Expected OutputExpected
NAME STATUS ROLES AGE VERSION node-1 Ready <none> 10d v1.26.0 node-2 Ready <none> 10d v1.26.0 node-3 Ready <none> 10d v1.26.0
Look at the resources and conditions of a specific node to find if it has enough CPU and memory.
Terminal
kubectl describe node node-1
Expected OutputExpected
Name: node-1 ... Allocated resources: (Total limits may be over 100 percent, i.e., overcommitted.) CPU Requests 400m CPU Limits 0 Memory Requests 512Mi Memory Limits 0 Conditions: Type Status ---- ------ Ready True
Key Concept

If a pod is stuck in Pending, check pod events and node resources to find why Kubernetes cannot schedule it.

Common Mistakes
Ignoring pod events and only looking at pod status.
Pod status 'Pending' alone does not explain the cause; events show detailed reasons like resource shortages.
Always run 'kubectl describe pod' to see events explaining the Pending state.
Assuming nodes have enough resources without checking.
Nodes may be full or have resource limits preventing new pods from running.
Check node resources and conditions with 'kubectl describe node' to confirm availability.
Not verifying node selectors or affinity rules in pod specs.
Pods may request to run only on specific nodes that do not exist or are full.
Review pod spec for node selectors or affinity and ensure matching nodes are available.
Summary
Use 'kubectl get pods' to identify pods stuck in Pending state.
Use 'kubectl describe pod <pod-name>' to see detailed events explaining why the pod is Pending.
Check node status and resources with 'kubectl get nodes' and 'kubectl describe node <node-name>' to find resource shortages or conditions blocking scheduling.

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