Custom Columns Output
The -o custom-columns flag lets you define exactly which fields appear as columns in kubectl output. It produces clean, tabular results without the complexity of JSONPath or Go templates.
Inline Column Definitions
Columns are defined as comma-separated HEADER:JSONPATH pairs:
# Show pod name, status, and IP
kubectl get pods -o custom-columns=NAME:.metadata.name,STATUS:.status.phase,IP:.status.podIP
# Output:
# NAME STATUS IP
# my-app Running 10.244.0.5
# web-server Running 10.244.1.3
Each column uses JSONPath syntax to extract the value from the resource.
More Examples
# Nodes with their OS and kernel version
kubectl get nodes -o custom-columns=\
NODE:.metadata.name,\
OS:.status.nodeInfo.osImage,\
KERNEL:.status.nodeInfo.kernelVersion
# Deployments with replica counts
kubectl get deploy -o custom-columns=\
NAME:.metadata.name,\
DESIRED:.spec.replicas,\
READY:.status.readyReplicas,\
AVAILABLE:.status.availableReplicas
# Pods with container images
kubectl get pods -o custom-columns=\
POD:.metadata.name,\
IMAGE:.spec.containers[*].image
Column Definitions from a File
For reusable or complex column sets, save them to a file:
# columns.txt
NAME NAMESPACE STATUS RESTARTS
.metadata.name .metadata.namespace .status.phase .status.containerStatuses[0].restartCount
# Use the column definition file
kubectl get pods -o custom-columns-file=columns.txt
The file format uses the first line as headers and the second line as JSONPath expressions, separated by whitespace.
Combining with Other Flags
# Custom columns with sorting
kubectl get pods -o custom-columns=NAME:.metadata.name,RESTARTS:.status.containerStatuses[0].restartCount \
--sort-by='.status.containerStatuses[0].restartCount'
# Custom columns across all namespaces
kubectl get pods -A -o custom-columns=\
NAMESPACE:.metadata.namespace,\
NAME:.metadata.name,\
NODE:.spec.nodeName
Key Takeaways
- Custom columns use the format
HEADER:.jsonpath.expression - Multiple columns are separated by commas
- Store complex definitions in a file with
custom-columns-file - Custom columns combine well with
--sort-byand-Aflags