Kubernetes: Find resources
9 Kubernetes commands: Find resources. Click a command to see what each part does.
Kubernetes: Find resourcesIndex
- Whole sheet137
- Basics: cluster, namespaces & resources17
- Get & list resources23
- Context & namespace3
- Find resources9
- Debug: describe, events, logs8
- Exec, port-forward, copy4
- Deploy, roll out, roll back, scale7
- Cleanup & nodes4
- Services, DNS & networking checks6
- Environment, config & secrets of workloads9
- Create, generate & apply YAML10
- Patch, label, annotate & scale9
- Delete & force delete6
- Nodes, scheduling & access control11
- Productivity: aliases, contexts & output11
Find resources9
kubectl get pods -A -o widePods in every namespace, with node and IPWhat each part does
kubectl get podslist pods-A--all-namespaces-o wideextra columns: node, pod IP, nominated node
kubectl get pods -A | grep <name>Find a pod by name fragmentWhat each part does
kubectl get pods -Aall pods in all namespaces (columns: NAMESPACE NAME READY STATUS…)|pipe the table into grepgrep <name>keep rows containing <name> (pod name, namespace or status like CrashLoopBackOff)
kubectl get pods -A --field-selector=status.phase!=RunningPods that are not RunningWhat each part does
--field-selectorfilter on object fields server-sidestatus.phase!=Runningphase is anything except Running (Pending, Failed, Succeeded, Unknown)
kubectl get pods -l app=<app> --show-labelsPods with a labelWhat each part does
-l app=<app>--selector: label must match (use "!key" to exclude, key in (a,b) for sets)--show-labelsadd a LABELS column
kubectl get pods -n <namespace> --sort-by=.status.containerStatuses[0].restartCountRecently restarted pods, sortedWhat each part does
--sort-by=<jsonpath>sort rows by a field of the object.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 namesWhat each part does
-o jsonpath=…print fields using a JSONPath template{.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 imageWhat each part does
-o custom-columns=…build your own tableNAME:.metadata.namecolumn header : JSONPath of the valueIMAGE:.spec.containers[*].imageimages of all containers
kubectl api-resourcesWhat resource types exist (and their short names)What each part does
api-resourcesevery resource type with short name (po, svc, deploy…), API group and whether it is namespaced
kubectl explain deployment.spec.strategyDocs for a fieldWhat each part does
explainbuilt-in documentation for resource fieldsdeployment.spec.strategypath to the field you want to understand
Nothing matches.
My DevOps Playbook by Angelo John Calleja