Kubernetes: Get & list resources (short names)
23 Kubernetes commands: Get & list resources (short names). Click a command to see what each part does.
Kubernetes: Get & list resources (short names)Index
- 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
Get & list resources (short names)23
kubectl get po -n <namespace>List podsWhat each part does
kubectl getlist resourcesposhort name for pods: NAME, READY, STATUS, RESTARTS, AGE-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get po -o wide -n <namespace>List pods with node and IPWhat each part does
popods-o wideadd the pod IP, the node it runs on and nominated node-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get svc -n <namespace>List servicesWhat each part does
svcshort name for services: TYPE, CLUSTER-IP, EXTERNAL-IP, PORT(S)-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get svc -o wide -n <namespace>List services with their selectorsWhat each part does
svc -o wideadd the SELECTOR column: which pod labels the service sends traffic to-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get endpointslices -l kubernetes.io/service-name=<service> -n <namespace>Which pods is a service sending traffic to?What each part does
endpointslicesthe actual pod IPs:ports behind services (kubectl get ep <service> on older clusters)-l kubernetes.io/service-name=<service>only the slices of this service-n <namespace>in this namespace (default: the context's namespace; -A for all)
Tip Empty ENDPOINTS means the selector matches no ready pods: compare kubectl get svc -o wide with kubectl get po --show-labels.
kubectl get deploy -n <namespace>List deploymentsWhat each part does
deploydeployments: READY (ready/desired), UP-TO-DATE, AVAILABLE-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get rs -n <namespace>List ReplicaSetsWhat each part does
rsReplicaSets; old ones with 0 replicas are kept for rollbacks-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get sts,ds -n <namespace>List StatefulSets and DaemonSetsWhat each part does
stsStatefulSetsdsDaemonSets: desired / current / ready per node-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get ing -AList ingressesWhat each part does
ingingresses: class, hosts, address, ports-Aall namespaces
kubectl get cm,secret -n <namespace>List ConfigMaps and SecretsWhat each part does
cmConfigMapssecretSecrets (values are not shown)-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get pv,pvc -AList volumes and claimsWhat each part does
pvPersistentVolumes (cluster-wide): capacity, status, claimpvcPersistentVolumeClaims: Bound / Pending-Aall namespaces for the claims
kubectl get scList storage classesWhat each part does
scStorageClasses; (default) marks the one used when a PVC names none
kubectl get jobs,cj -n <namespace>List jobs and cronjobsWhat each part does
jobsJobs: completions, durationcjCronJobs: schedule, last schedule, active-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get hpa -n <namespace>List autoscalersWhat each part does
hpaHorizontalPodAutoscalers: target metric vs current, min/max/current replicas-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get sa -n <namespace>List service accountsWhat each part does
saServiceAccounts-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get netpol -n <namespace>List network policiesWhat each part does
netpolNetworkPolicies and the pods they select-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get crdList custom resource typesWhat each part does
crdCustomResourceDefinitions installed by operators and add-ons
kubectl api-resources --sort-by=name -o wideEvery short name and resource typeWhat each part does
api-resourcesevery resource type: SHORTNAMES (po, svc, deploy...), API group, namespaced, verbs--sort-by=namealphabetical-o wideinclude supported verbs
kubectl get po -l 'env in (prod,staging),tier!=frontend'Pods by set-based label selectorWhat each part does
-l '...'label selectorenv in (prod,staging)label env is one of thesetier!=frontendand tier is not frontend
kubectl get po -A -o wide --field-selector spec.nodeName=<node>Pods on a specific nodeWhat each part does
-A -o wideall namespaces, with node column--field-selector spec.nodeName=<node>only pods scheduled on that node
kubectl get po -o name -n <namespace>Just the names (for scripts)What each part does
-o nameprint type/name per line, e.g. pod/api-7d9f, ready for xargs-n <namespace>in this namespace (default: the context's namespace; -A for all)
kubectl get po -A -o jsonpath='{range .items[*]}{range .spec.containers[*]}{.image}{"\n"}{end}{end}' | sort | uniq -cEvery image running in the clusterWhat each part does
-o jsonpath='...'loop over pods and their containers, print each image| sort | uniq -ccount pods per image
kubectl get po -w -n <namespace>Watch resources changeWhat each part does
-wkeep printing changes (status, restarts) until Ctrl+C-n <namespace>in this namespace (default: the context's namespace; -A for all)
Nothing matches.
My DevOps Playbook by Angelo John Calleja