Show Menu
Cheatography

Kubernetes Cheat Sheet (DRAFT) by

kubernetes command cheat sheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Contexts

kubectl config get-co­ntexts
Show contexts
kubectl config curren­t-c­ontext
Show current context
kubectl config use-co­ntext <my­-cl­ust­er-­nam­e>
Switch contet to another cluster
kubectl config set-co­ntext --current --name­spa­ce=­<na­mes­pac­e>
Change namespace
 

Logs

kubectl logs <po­d>
Show logs (stdout) of a pod
kubectl logs -l <la­bel­>=<­val­ue>
Show logs (stdout) of pods that match a label
kubectl logs <po­d> --previous
Show logs of a previous instan­tiation of a container
kubectl logs <po­d> -c <co­nta­ine­r>
Show logs for a specific container in a pod (i.e. init container)
kubectl logs -f <po­d>
Following logs from a pod
kubectl logs -f -l <la­bel­>=<­val­ue> --all-­con­tainers
Follow all logs from a pod that match a label
kubectl logs <po­d> --v=<0­:9>
Show logs with verbosity level of logs from 0 - 9

Services

kubectl get services
Get all services in the current namespace
kubectl get service --all-­nam­espaces
Get services in all namespaces
kubectl get service -o wide
Get services with more details
kubectl get service <se­rvi­ce> -o yaml
Get the yaml for a services
kubectl describe service <se­rvi­ce>
Inspect a service
kubectl get service --show­-labels
Get service's labels
kubectl get service -l <la­bel­>=<­val­ue>
Get services that match a labels