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

Common JSONPath patterns for kubectl output.

List pod names

Print all pod names in a namespace.

bashANYjsonpathpods
bash
kubectl get pods -n payments -o jsonpath='{.items[*].metadata.name}'

Print all pod names in a namespace.

List pod images

Print pod names and container images.

bashANYjsonpathimages
bash
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

Print node names with internal IPs.

bashANYjsonpathnodes
bash
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

Print service port mappings.

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

Print service port mappings.

List secret keys

Print the secret data object keys and values.

bashANYjsonpathsecret
bash
kubectl get secret app-secret -n payments -o jsonpath='{.data}'

Print the secret data object keys and values.

List pod restart counts

Print pod restart counts.

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

Print pod restart counts.

List ingress hosts

Print ingress names and hosts.

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

Print ingress names and hosts.

List pvc capacities

Print PVC names and bound storage sizes.

bashANYjsonpathpvc
bash
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

Alternative output strategies beyond JSONPath.

Node capacity custom columns

Show capacity data in a concise table.

bashANYoutputcustom-columnsnodes
bash
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

Render output using Go templates.

bashANYoutputgo-template
bash
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

Pipe kubectl JSON into jq for flexible filtering.

bashANYjqjson
bash
kubectl get deployment web -n payments -o json | jq

Pipe kubectl JSON into jq for flexible filtering.

Search YAML output

Extract YAML fields with yq.

bashANYyamlyq
bash
kubectl get deployment web -n payments -o yaml | yq '.spec.template.spec.containers[].image'

Extract YAML fields with yq.

Kustomize with kubectl

Preview and apply overlays and generated resources.

Render kustomization

Build a kustomization without applying it.

bashANYkustomizerender
bash
kubectl kustomize overlays/prod

Build a kustomization without applying it.

Apply kustomization

Apply resources from a kustomization directory.

bashANYkustomizeapply
bash
kubectl apply -k overlays/prod

Apply resources from a kustomization directory.

Delete kustomized resources

Delete resources generated by a kustomization.

bashANYkustomizedelete
bash
kubectl delete -k overlays/prod

Delete resources generated by a kustomization.

Diff kustomized resources

Preview the changes from a kustomization.

bashANYkustomizediff
bash
kubectl diff -k overlays/prod

Preview the changes from a kustomization.

Apply and prune kustomization

Apply a kustomization and prune matching managed objects.

bashANYkustomizeprune
bash
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

Generate YAML that can be committed into Kustomize overlays.

bashANYkustomizedry-runyaml
bash
kubectl create configmap app-config --from-file=app.env -o yaml --dry-run=client

Generate YAML that can be committed into Kustomize overlays.