# get all common resources (pod, svc, sts)kubectl get all# shortcut to target podskubectl get po# ==kubectl get pods# shortcut to target namespacekubectl get ns# ==kubectl get namespaces# shortcut to target replicasetskubectl get rs# ==kubectl get replicasets# shortcut to target daemonsetskubectl get ds# ==kubectl get daemonsets# shortcut to target serviceskubectl get svc# ==kubectl get services# shortcut to target configmapskubectl get cm# ==kubectl get configmap# shortcut to target statefulsetskubectl get sts# ==kubectl get statefulset
Help
# access to resource documentationkubectl explain pods# use json path to go furtherkubectl explain pods.spec.containers# list all supported resourceskubectl api-resources# access to the list of resource specifications# each resource can be used in the YAML description# e.g. pods.spec.initContainers will be written in the# pod descriptor:# ```yaml# spec:# initContainers:# - name: foobar# ```kubectl explain <resource_name>.speckubectl explain pods.spec# nuke allkubectl delete all --all# get multiple resources in one line# e.g. get pods and replicasetskubectl get po,rs
# start a podkubectl run <pod_name> --image <image_name> --port <port># list podskubectl get po# get pods' metadatakubectl describe po# execute command in podkubectl exec -it <pod_name> -- <command># execute shell command on specific containerkubectl exec -it <pod_name> -c <container_name> -- <command># delete a podkubectl delete po <pod_name># generate k8s pod description filekubectl run <pod_name> --image <image_name> --port <port> --dry-run client -o yaml > <pod_name>.yml# get pod ipkubectl get -o go-template --template='{{.status.podIP}}' pod whoami# show pod labelskubectl get po --show-labels# add labelskubectl label pod <pod_name> <label_name>=<label_value># update a labelkubectl label pod <pod_name> <label_name>=<label_value> --overwrite# get pods with their labels displayed in columnskubectl get po --label-columns label1,label2# get pods that have the label 'foobar' with value 'barfoo'kubectl get po --selector foobar=barfookubectl get po -l foobar=barfoo# get pods that do not have the label 'foobar'kubectl get po --selector '!foobar'# get pods that have label 'run' with value 'foo' or 'bar' and 'release' label is not specifiedkubectl get po --selector 'run in (foo,bar),!release'# get all annotationskubectl get po -o json <pod_name> | jq .metadata.annotations# get pod namekubectl get po -l app=front -o name# add annotation to a podkubectl annotate po <pod_name> <annotation_name>=<annotation_value># read logs# <container_name> mandatory if the pod has multiple containerskubectl logs <pod_name> -c <container_name># followkubectl logs -f <pod_name>
# get replicasetskubectl get rs# change scalingkubectl scale rs <rs_name> --replicas=<N># delete a replicaset, it will also delete the associated pods!kubectl delete rs <rs_name>