Skip to content

Kubernetes: Find resources

9 Kubernetes commands: Find resources. Click a command to see what each part does.

Index
9 items
Click a command to see what each part does.

Find resources9

  • kubectl get pods -A -o widePods in every namespace, with node and IP

    What each part does

    1. kubectl get podslist pods
    2. -A--all-namespaces
    3. -o wideextra columns: node, pod IP, nominated node
  • kubectl get pods -A | grep <name>Find a pod by name fragment

    What each part does

    1. kubectl get pods -Aall pods in all namespaces (columns: NAMESPACE NAME READY STATUS…)
    2. |pipe the table into grep
    3. grep <name>keep rows containing <name> (pod name, namespace or status like CrashLoopBackOff)
  • kubectl get pods -A --field-selector=status.phase!=RunningPods that are not Running

    What each part does

    1. --field-selectorfilter on object fields server-side
    2. status.phase!=Runningphase is anything except Running (Pending, Failed, Succeeded, Unknown)
  • kubectl get pods -l app=<app> --show-labelsPods with a label

    What each part does

    1. -l app=<app>--selector: label must match (use "!key" to exclude, key in (a,b) for sets)
    2. --show-labelsadd a LABELS column
  • kubectl get pods -n <namespace> --sort-by=.status.containerStatuses[0].restartCountRecently restarted pods, sorted

    What each part does

    1. --sort-by=<jsonpath>sort rows by a field of the object
    2. .status.containerStatuses[0].restartCountrestart count of the first container: crash-looping pods end up last
  • kubectl get pods -o jsonpath='{.items[*].metadata.name}'Just the pod names

    What each part does

    1. -o jsonpath=…print fields using a JSONPath template
    2. {.items[*].metadata.name}the name of every item in the list
  • kubectl get pods -o custom-columns='NAME:.metadata.name,IMAGE:.spec.containers[*].image'Custom table: pod and image

    What each part does

    1. -o custom-columns=…build your own table
    2. NAME:.metadata.namecolumn header : JSONPath of the value
    3. IMAGE:.spec.containers[*].imageimages of all containers
  • kubectl api-resourcesWhat resource types exist (and their short names)

    What each part does

    1. api-resourcesevery resource type with short name (po, svc, deploy…), API group and whether it is namespaced
  • kubectl explain deployment.spec.strategyDocs for a field

    What each part does

    1. explainbuilt-in documentation for resource fields
    2. deployment.spec.strategypath to the field you want to understand

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…