Kubernetes JSONPath and Kustomize Cheat Sheet

JSONPath recipes, custom output patterns, jq/yq workflows, and Kustomize commands supported by kubectl.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## JSONPath Output Recipes
List pod names
kubectl get pods -n payments -o jsonpath='{.items[*].metadata.name}'

# Print all pod names in a namespace.

List pod images
kubectl get pods -n payments -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"
"}{end}'

# Print pod names and container images.

List node internal IPs
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.addresses[?(@.type=="InternalIP")].address}{"
"}{end}'

# Print node names with internal IPs.

List service ports
kubectl get svc web -n payments -o jsonpath='{range .spec.ports[*]}{.name}{":"}{.port}{"->"}{.targetPort}{"
"}{end}'

# Print service port mappings.

List secret keys
kubectl get secret app-secret -n payments -o jsonpath='{.data}'

# Print the secret data object keys and values.

List pod restart counts
kubectl get pods -n payments -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.containerStatuses[*].restartCount}{"
"}{end}'

# Print pod restart counts.

List ingress hosts
kubectl get ingress -n payments -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.rules[*].host}{"
"}{end}'

# Print ingress names and hosts.

List pvc capacities
kubectl get pvc -n data -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.capacity.storage}{"
"}{end}'

# Print PVC names and bound storage sizes.

## Go Templates, Custom Columns, and jq-Friendly Patterns
Node capacity custom columns
kubectl get nodes -o custom-columns=NAME:.metadata.name,CPU:.status.capacity.cpu,MEM:.status.capacity.memory,EPHEMERAL:.status.capacity.ephemeral-storage

# Show capacity data in a concise table.

Go template pod phase
kubectl get pods -n payments -o go-template='{{range .items}}{{.metadata.name}}{{"\t"}}{{.status.phase}}{{"
"}}{{end}}'

# Render output using Go templates.

Pretty JSON with jq
kubectl get deployment web -n payments -o json | jq

# Pipe kubectl JSON into jq for flexible filtering.

Search YAML output
kubectl get deployment web -n payments -o yaml | yq '.spec.template.spec.containers[].image'

# Extract YAML fields with yq.

## Kustomize with kubectl
Render kustomization
kubectl kustomize overlays/prod

# Build a kustomization without applying it.

Apply kustomization
kubectl apply -k overlays/prod

# Apply resources from a kustomization directory.

Delete kustomized resources
kubectl delete -k overlays/prod

# Delete resources generated by a kustomization.

Diff kustomized resources
kubectl diff -k overlays/prod

# Preview the changes from a kustomization.

Apply and prune kustomization
kubectl apply -k overlays/prod --prune -l app.kubernetes.io/managed-by=kustomize

# Apply a kustomization and prune matching managed objects.

Generate configmap YAML dry-run
kubectl create configmap app-config --from-file=app.env -o yaml --dry-run=client

# Generate YAML that can be committed into Kustomize overlays.