Output Formats
kubectl can display data in several formats. Choosing the right one depends on whether you are browsing, debugging, scripting, or extracting specific values.
Default Table Output
With no flags, kubectl shows a simple table:
kubectl get pods
NAME READY STATUS RESTARTS AGE
my-app-7d4b8c6f5-abc12 1/1 Running 0 2h
my-app-7d4b8c6f5-def34 1/1 Running 0 2h
Wide Output
The -o wide flag adds extra columns like node name and IP address:
kubectl get pods -o wide
This is useful when you need to know which node a Pod is running on or what its IP is without running describe.
YAML Output
The -o yaml flag shows the complete resource definition:
kubectl get deployment my-app -o yaml
This is helpful for understanding exactly what Kubernetes knows about a resource, including all default values that were set automatically.
JSON Output
The -o json flag outputs JSON, which works well with tools like jq:
kubectl get pod my-app -o json | jq '.status.phase'
Name Output
The -o name flag returns just the resource type and name, perfect for scripting:
kubectl get pods -o name
pod/my-app-7d4b8c6f5-abc12
pod/my-app-7d4b8c6f5-def34
JSONPath
The -o jsonpath flag lets you extract specific fields using JSONPath expressions:
# Get just the pod IP
kubectl get pod my-app -o jsonpath='{.status.podIP}'
# Get all pod names
kubectl get pods -o jsonpath='{.items[*].metadata.name}'
# Get names and statuses with formatting
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}'
Custom Columns
Build your own table with exactly the columns you want:
kubectl get pods -o custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName
Key Takeaways
- Use
-o widefor a quick view with extra details - Use
-o yamlor-o jsonto see the full resource definition - Use
-o namein scripts to get just the resource identifiers - Use
-o jsonpathto extract specific fields for automation - Custom columns let you build your own tailored output tables