Skip to content

Kubernetes: Get & list resources (short names)

23 Kubernetes commands: Get & list resources (short names). Click a command to see what each part does.

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

Get & list resources (short names)23

  • kubectl get po -n <namespace>List pods

    What each part does

    1. kubectl getlist resources
    2. poshort name for pods: NAME, READY, STATUS, RESTARTS, AGE
    3. -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 IP

    What each part does

    1. popods
    2. -o wideadd the pod IP, the node it runs on and nominated node
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get svc -n <namespace>List services

    What each part does

    1. svcshort name for services: TYPE, CLUSTER-IP, EXTERNAL-IP, PORT(S)
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get svc -o wide -n <namespace>List services with their selectors

    What each part does

    1. svc -o wideadd the SELECTOR column: which pod labels the service sends traffic to
    2. -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

    1. endpointslicesthe actual pod IPs:ports behind services (kubectl get ep <service> on older clusters)
    2. -l kubernetes.io/service-name=<service>only the slices of this service
    3. -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 deployments

    What each part does

    1. deploydeployments: READY (ready/desired), UP-TO-DATE, AVAILABLE
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get rs -n <namespace>List ReplicaSets

    What each part does

    1. rsReplicaSets; old ones with 0 replicas are kept for rollbacks
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get sts,ds -n <namespace>List StatefulSets and DaemonSets

    What each part does

    1. stsStatefulSets
    2. dsDaemonSets: desired / current / ready per node
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get ing -AList ingresses

    What each part does

    1. ingingresses: class, hosts, address, ports
    2. -Aall namespaces
  • kubectl get cm,secret -n <namespace>List ConfigMaps and Secrets

    What each part does

    1. cmConfigMaps
    2. secretSecrets (values are not shown)
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get pv,pvc -AList volumes and claims

    What each part does

    1. pvPersistentVolumes (cluster-wide): capacity, status, claim
    2. pvcPersistentVolumeClaims: Bound / Pending
    3. -Aall namespaces for the claims
  • kubectl get scList storage classes

    What each part does

    1. scStorageClasses; (default) marks the one used when a PVC names none
  • kubectl get jobs,cj -n <namespace>List jobs and cronjobs

    What each part does

    1. jobsJobs: completions, duration
    2. cjCronJobs: schedule, last schedule, active
    3. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get hpa -n <namespace>List autoscalers

    What each part does

    1. hpaHorizontalPodAutoscalers: target metric vs current, min/max/current replicas
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get sa -n <namespace>List service accounts

    What each part does

    1. saServiceAccounts
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get netpol -n <namespace>List network policies

    What each part does

    1. netpolNetworkPolicies and the pods they select
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)
  • kubectl get crdList custom resource types

    What each part does

    1. crdCustomResourceDefinitions installed by operators and add-ons
  • kubectl api-resources --sort-by=name -o wideEvery short name and resource type

    What each part does

    1. api-resourcesevery resource type: SHORTNAMES (po, svc, deploy...), API group, namespaced, verbs
    2. --sort-by=namealphabetical
    3. -o wideinclude supported verbs
  • kubectl get po -l 'env in (prod,staging),tier!=frontend'Pods by set-based label selector

    What each part does

    1. -l '...'label selector
    2. env in (prod,staging)label env is one of these
    3. tier!=frontendand tier is not frontend
  • kubectl get po -A -o wide --field-selector spec.nodeName=<node>Pods on a specific node

    What each part does

    1. -A -o wideall namespaces, with node column
    2. --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

    1. -o nameprint type/name per line, e.g. pod/api-7d9f, ready for xargs
    2. -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 cluster

    What each part does

    1. -o jsonpath='...'loop over pods and their containers, print each image
    2. | sort | uniq -ccount pods per image
  • kubectl get po -w -n <namespace>Watch resources change

    What each part does

    1. -wkeep printing changes (status, restarts) until Ctrl+C
    2. -n <namespace>in this namespace (default: the context's namespace; -A for all)

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/…