kubectl get -- Your Most-Used Command
kubectl get is the command you will use more than any other. It lists resources in your cluster and is the starting point for almost every troubleshooting session.
Basic Syntax
The basic pattern is straightforward:
kubectl get <resource-type>
Replace <resource-type> with the kind of resource you want to see.
Common Resources
Here are the resources you will query most often:
# List all pods in the current namespace
kubectl get pods
# List all services
kubectl get services
# List all deployments
kubectl get deployments
# List all namespaces
kubectl get namespaces
# List all nodes
kubectl get nodes
You can also use short names to save typing:
# Short names work the same way
kubectl get po # pods
kubectl get svc # services
kubectl get deploy # deployments
kubectl get ns # namespaces
kubectl get no # nodes
Output Formats
The default output is a simple table, but kubectl supports several formats:
Wide output shows additional columns:
kubectl get pods -o wide
This adds columns like the node the Pod is running on and its IP address.
YAML output shows the full resource definition:
kubectl get pod my-app -o yaml
JSON output is useful for scripting and piping to tools like jq:
kubectl get pod my-app -o json
# Use jq to extract a specific field
kubectl get pod my-app -o json | jq '.status.phase'
Custom columns let you pick exactly what you want to see:
kubectl get pods -o custom-columns=NAME:.metadata.name,STATUS:.status.phase,IP:.status.podIP
Using --all-namespaces
By default, kubectl only shows resources in your current namespace. To see resources across the entire cluster:
# Show pods in all namespaces
kubectl get pods --all-namespaces
# Short flag version
kubectl get pods -A
The -A flag is a shortcut you will use constantly, especially when you are not sure which namespace a resource is in.
Filtering and Sorting
You can filter resources using labels:
# Get pods with a specific label
kubectl get pods -l app=nginx
# Get pods matching multiple labels
kubectl get pods -l app=nginx,environment=production
Sort by a specific field:
# Sort pods by creation time
kubectl get pods --sort-by=.metadata.creationTimestamp
# Sort by restart count
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
Watching for Changes
Add the --watch flag to see real-time updates:
# Watch pods as they change status
kubectl get pods --watch
This keeps the terminal open and prints a new line whenever a Pod's state changes. Press Ctrl+C to stop watching.
Key Takeaways
kubectl getlists resources and is your go-to command for cluster visibility- Use short names like
po,svc, anddeployto save time - Output formats (
-o wide,-o yaml,-o json) reveal different levels of detail - The
-Aflag shows resources across all namespaces - Labels (
-l) let you filter resources, and--watchprovides live updates