Skip to content

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:

kubectl get pods -n default

Wide output with extra columns (node, IP):

kubectl get pods -o wide -n default

Full YAML output for a single resource:

kubectl get pod <pod-name> -o yaml

Extract a specific field with jsonpath:

kubectl get pod <pod-name> -o jsonpath='{.status.podIP}'

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:

kubectl get pods --show-labels

Filter by label:

kubectl get pods -l app=nginx -o wide

Sort by a field:

kubectl get pods --sort-by=.status.startTime

Get resources across all namespaces:

kubectl get pods -A -o wide

What to Look For

  • -o wide adds 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-labels reveals label-based grouping and selector membership

Common Mistakes

  • Using -o yaml on multiple resources and getting overwhelmed (filter first)
  • Incorrect jsonpath syntax (missing range for lists, wrong field paths)
  • Forgetting -A flag when a pod is in an unexpected namespace
  • Not using --field-selector to filter by status server-side

Cleanup

No cleanup needed. These are read-only commands.