kubectl Output Formatting Options
What you'll learn: How to control and customize the output of kubectl commands to display exactly the data you need in different formats.
Why Output Formatting Matters
When you run kubectl get or kubectl describe, the default output is human-readable tables. But sometimes you need raw data for scripting, detailed configuration for debugging, or just specific fields. That's where output formatting flags come in.
Think of it like asking a librarian for book information: you can get a simple card with title and author (default), the full catalog entry (verbose), or just the ISBN number (custom field).
The -o Flag Family
The -o (output) flag lets you format kubectl command results:
Common formats:
-o json– Full resource data in JSON format, perfect for scripts or APIs-o yaml– Full resource data in YAML, easier to read than JSON-o wide– Extended table view with more columns (like node name, IP addresses)-o name– Just the resource type and name (e.g.,pod/nginx-abc123)
Precise extraction:
-o custom-columns=– Define exactly which columns to display with column names and JSONPath expressions-o jsonpath='{...}'– Extract specific fields using JSONPath query syntax for surgical data retrieval
Real-World Use Cases
Use wide when you need quick extra details. Use json or yaml when debugging configurations or feeding data to other tools. Use custom-columns when building reports. Use jsonpath when extracting a single field value for automation scripts.
These formatting options transform kubectl from a simple viewer into a powerful data extraction tool that integrates seamlessly with other command-line utilities and automation pipelines.
Key Takeaway: The -o flag gives you complete control over kubectl output—from human-friendly tables to machine-parseable JSON to laser-focused field extraction—making kubectl adaptable to any workflow.