User Tools

Site Tools


kubernetes:kubectl_cheatsheet

[CHEATSHEET] kubectl

show current config

kubectl config view

list clusters

kubectl config get-clusters

list current cluster/context

kubectl config use-context ${CLUSTER}

switch cluster/context

kubectl config current-context

list namespaces

kubectl get ns

list namespaces from ALL clusters

kubectl config get-clusters  | grep -Ev "NAME" | while read CLUSTER ; do if kubectl config use-context ${CLUSTER} >/dev/null ; then  echo "##### ${CLUSTER}" ; kubectl get ns | grep -Ev "^NAME" ;fi  ; done

list namespaces detailed

kubectl describe ns

change namespace

kubectl config set-context --current --namespace=NAMESPACE_NAME

List all pods

kubectl get pod --all-namespaces

less info:

kubectl get pod -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName --all-namespaces

List cronjobs

kubectl get cronjob -n ${NAMESPACE}

Get cronjob detail information

kubectl describe cronjob ${CRONJOB_ID} -n ${NAMESPACE}

List ALL cronjobs fron all namespaces

kubectl get cronjobs -A

List ALL cronjobs fron all namespaces in ALL clusters

kubectl config get-clusters  | grep -Ev "NAME" | while read CLUSTER ; do if kubectl config use-context ${CLUSTER} >/dev/null ; then  echo "##### ${CLUSTER}" ; kubectl get cronjob -A ; fi ;done
kubernetes/kubectl_cheatsheet.txt · Last modified: 2024/11/26 16:33 by dodger