Drill: Effective kubectl get Output Formats¶
Goal¶
Use kubectl get with various output formats including wide, yaml, jsonpath, and custom-columns for efficient inspection.
Setup¶
- kubectl configured with access to a Kubernetes cluster
- At least one namespace with running pods
Commands¶
Default output:
Wide output with extra columns (node, IP):
Full YAML output for a single resource:
Extract a specific field with jsonpath:
Extract multiple fields:
kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\t"}{.status.podIP}{"\n"}{end}'
Custom columns for readable tabular output:
kubectl get pods -o custom-columns='NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName,IP:.status.podIP'
Get all resources with labels:
Filter by label:
Sort by a field:
Get resources across all namespaces:
What to Look For¶
-o wideadds node name and pod IP, essential for placement debugging- jsonpath can extract deeply nested fields for scripting
- custom-columns give you a readable table with exactly the fields you need
--show-labelsreveals label-based grouping and selector membership
Common Mistakes¶
- Using
-o yamlon multiple resources and getting overwhelmed (filter first) - Incorrect jsonpath syntax (missing range for lists, wrong field paths)
- Forgetting
-Aflag when a pod is in an unexpected namespace - Not using
--field-selectorto filter by status server-side
Cleanup¶
No cleanup needed. These are read-only commands.