List Kubernetes resources with flexible output options.
low risk
kubectl get is the primary read command for K8s. It lists resources with status. Output formats range from human-friendly tables to machine-parseable JSON/YAML. The -w flag watches for changes. Mastering -o and --field-selector transforms kubectl from a query tool into an automation backbone.
| Flag | Meaning |
|---|---|
-n --namespace | Target namespace |
-A --all-namespaces | All namespaces |
-o --output | Format: json, yaml, wide, jsonpath, custom-columns |
-w --watch | Watch for changes |
--field-selector | Filter by field values |
-l --selector | Filter by label |
kubectl get pods -A -o wideAll pods across namespaces with node info · explain & risk-check →kubectl get pods -l app=nginx -wWatch nginx pods for changes · explain & risk-check →kubectl get pods -o jsonpath='{.items[*].metadata.name}'Extract pod names for scripting · explain & risk-check →kubectl get nodes -o custom-columns=NODE:.metadata.name,STATUS:.status.conditions[-1].typeCustom columns output · explain & risk-check →kubectl get events -A --sort-by='.lastTimestamp' | tail -20Recent cluster events · explain & risk-check →Use `kubectl get pods -o json | jq -r '.items[] | select(.status.phase!="Running") | .metadata.name'` to programmatically find non-running pods — far more reliable than parsing tabular output.
Reference text is hand-written and may be incomplete — check man kubectl for your version. Test destructive commands on a non-production system first.