kubectl get pods all namespaces: Complete Guide
kubectl get pods --all-namespaces (or -A) is the single most-used command in Kubernetes troubleshooting — and knowing how to filter, sort, and format its output turns it from a scroll of rows into actual answers. This guide covers the flags that matter and the patterns that don't show up in --help.
Table of Contents
- Basic Command
- Filtering Results
- Common Use Cases
- Advanced Output Formatting
- Troubleshooting
- Best Practices
- FAQ
Basic Command
The simplest way to list all pods across all namespaces:
kubectl get pods --all-namespaces
Or using the shorter alias (memorize this one — you'll type it hundreds of times):
kubectl get pods -A
Output Explanation
NAMESPACE NAME READY STATUS RESTARTS AGE
default nginx-7db9fccd9b-2x4kl 1/1 Running 0 2d
kube-system coredns-5644d7b6d9-k8w9v 1/1 Running 0 2d
kube-system etcd-minikube 1/1 Running 0 2d
- NAMESPACE: Which namespace the pod belongs to
- NAME: Unique name of the pod
- READY: Running containers / Total containers
- STATUS: Current pod status (Running, Pending, Failed, etc.)
- RESTARTS: Number of container restarts
- AGE: How long the pod has been running
The -A flag works on every resource type, not just pods — kubectl get services -A, kubectl get secrets -A — the flag is universal.
Filtering Results
Filter by Namespace
# Specific namespace
kubectl get pods -n kube-system
# Multiple namespaces
kubectl get pods -n kube-system -n default
-A shows everything, -n scopes to one — the second -n doesn't chain, so for "several namespaces" you still use -A and filter downstream.
Filter by Label
# All pods with specific label
kubectl get pods --all-namespaces -l app=nginx
# Multiple labels
kubectl get pods --all-namespaces -l app=nginx,tier=frontend
Labels are the scalable filter — a well-labeled cluster turns "find all the frontend pods" into a one-liner instead of a namespace-by-namespace hunt.
Filter by Status
# Only running pods
kubectl get pods --all-namespaces --field-selector=status.phase=Running
# Only failed pods
kubectl get pods --all-namespaces --field-selector=status.phase=Failed
Field selectors work on structured fields (status.phase, spec.nodeName), labels work on metadata you set — they're the two complementary filters.
Filter by Node
# Pods running on a specific node
kubectl get pods --all-namespaces --field-selector=spec.nodeName=worker-3
Useful during a drain or node troubleshooting — "what's running on the node I'm about to take down?"
Common Use Cases
1. Find CrashLoopBackOff Pods
kubectl get pods --all-namespaces --field-selector=status.phase!=Running
Or narrower — !Running && !Succeeded filters out completed jobs too.
2. Check Resource Usage
kubectl top pods --all-namespaces
Requires metrics-server installed; without it you get a "Metrics API not available" error.
3. Find Pods with High Restart Counts
kubectl get pods --all-namespaces --sort-by='.status.containerStatuses[0].restartCount'
The RESTARTS column is your canary — a pod with 40 restarts in an hour is unhealthy even while "Running."
4. List Pods with Their IPs
kubectl get pods --all-namespaces -o wide
-o wide adds NODE and IP columns — the two details you need before you can tell whether a problem is pod-level or node-level.
5. Get Pod Details in JSON
kubectl get pods --all-namespaces -o json
6. Show Init Containers and Ephemeral Containers
kubectl get pods -A -o json | jq '.items[] | select(.status.initContainerStatuses != null) | .metadata.name'
Init containers don't appear in the default output — if a pod is stuck in Init:0/2, this is how you see which init container is blocking it.
Advanced Output Formatting
Custom Columns
kubectl get pods -A -o custom-columns=\
'NAMESPACE:.metadata.namespace,\
POD:.metadata.name,\
STATUS:.status.phase,\
IP:.status.podIP'
Custom columns let you build the exact table you need — useful when piping into awk/column for reporting.
JSONPath for Scripting
# Get just the pod names
kubectl get pods -A -o jsonpath='{.items[*].metadata.name}'
# Get pods and their container images
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'
jsonpath is the scripting-friendly output format — machine-parseable, compact, and stable across kubectl versions.
Filtering with jq (More Powerful)
# List pods and their restart counts
kubectl get pods -A -o json | \
jq -r '.items[] | "\(.metadata.namespace)\t\(.metadata.name)\t\(.status.containerStatuses[0].restartCount)"'
For complex filtering — "all pods with an env var containing PASSWORD," "all pods on nodes without a given label" — jq does what kubectl's built-in filters can't.
Troubleshooting
Pod Not Showing Up
If a pod isn't appearing in the list:
- Check if it exists in a specific namespace:
kubectl get pods -n <namespace>
- Verify you have permissions:
kubectl auth can-i list pods --all-namespaces
- Check if namespace exists:
kubectl get namespaces
Command Timeout
If the command times out:
# Increase timeout
kubectl get pods --all-namespaces --request-timeout=30s
On very large clusters (10k+ pods), the full -A scan can take a while — narrow with -n or -l instead of waiting for the whole thing.
Permission Denied
Error from server (Forbidden): pods is forbidden: User "system:serviceaccount:..." cannot list resource "pods"
You need cluster-level RBAC — a ClusterRole with list pods permission, or cluster-admin. Your account might only have permissions in a specific namespace.
Best Practices
1. Always Use --all-namespaces When Debugging
Pods get created in unexpected namespaces — a kubectl apply on the wrong context puts pods in default, a Helm release targets kube-system, a job lands in a forgotten namespace. The pod that's "missing" is often in a namespace you didn't look in.
2. Save Output for Debugging
# Save to file for analysis
kubectl get pods --all-namespaces -o wide > pods.txt
A snapshot lets you diff "now" vs "10 minutes ago" — the missing row or the RESTARTS jump is often the smoking gun.
3. Combine with Watch for Monitoring
# Watch pods in real-time
kubectl get pods --all-namespaces --watch
Or the cleaner watch wrapper:
watch -n 2 'kubectl get pods -A'
--watch streams live updates; watch re-runs the command — the second gives you a proper diff and survives network blips.
4. Use Aliases
Add to ~/.bashrc or ~/.zshrc:
alias k='kubectl'
alias kgpa='kubectl get pods --all-namespaces'
alias kgpa-w='kubectl get pods --all-namespaces -o wide'
alias kgpa-f='kubectl get pods --all-namespaces --field-selector'
kgpa alone saves real keystrokes; the filtered variants save the flag-fiddling.
FAQ
Q: What's the difference between -A and -n?
-A (or --all-namespaces) lists resources across all namespaces in the cluster. -n <name> scopes to a single namespace. They're mutually exclusive — -A -n default errors.
Q: Why doesn't --all-namespaces work on nodes?
Nodes are cluster-scoped resources — they don't live in namespaces. kubectl get nodes is already "all namespaces"; the flag is irrelevant on cluster-scoped resources.
Q: Can I see pods across multiple clusters?
Not in a single kubectl command — kubectl is bound to one context. You'd run the command per context (kubectl config get-contexts to list), or use a multi-cluster tool like k9s or Lens that fans out across contexts.
Related Articles
Our tutorials and troubleshooting runbooks are written by a DevOps practitioner with hands-on experience operating Kubernetes, Terraform, CI/CD pipelines, and Linux infrastructure in production. Commands, manifests, and configurations are verified against current tooling releases. Learn more about our editorial process or report a correction or outdated flag.