Show Menu
Cheatography

Kubernetes Cheat Sheet (DRAFT) by

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

Creating Objects

Create resources (multiple allowed)
kubectl create -f ./x.yaml ./y.yaml 
Start a single instance of nginx
kubectl run nginx --imag­e=nginx  
Get the docume­ntation
kubectl explain pods,svc 

Viewing, Finding Resources

List all services in the namespace
kubectl get services
All namespace
kubectl get pods --all-­nam­espaces
More details
kubectl get pods -o wide 
List Services Sorted by Name
kubectl get services --sort­-by­=.m­eta­dat­a.name
Get using label
kubectl get pods --sele­cto­r=a­pp=­cas­sandra
Describe commands with verbose output
kubectl describe nodes my-node

Updating Resources

Rolling update pods of fronte­nd-v1
kubectl rollin­g-u­pdate fronte­nd-v1 -f fronte­nd-­v2.json
Change the name of the resource and update the image
kubectl rollin­g-u­pdate fronte­nd-v1 fronte­nd-v2 --imag­e=i­mage:v2
Update the pods image of frontend
kubectl rollin­g-u­pdate frontend --imag­e=i­mage:v2
Abort existing rollout in progress
kubectl rollin­g-u­pdate fronte­nd-v1 fronte­nd-v2 --rollback
Force replace, delete and then re-create the resource. Will cause a service outage.
kubectl replace --force -f ./pod.json
Add a Label
kubectl label pods my-pod new-la­bel­=aw­esome
Auto scale a deployment "­foo­"
kubectl autoscale deployment foo --min=2 --max=10

Scaling Resources

Scale a replicaset named 'foo' to 3
kubectl scale --repl­icas=3 rs/foo
Scale a resource specified in "­foo.ya­ml" to 3
kubectl scale --repl­icas=3 -f foo.yaml
If the deployment named mysql's current size is 2, scale mysql to 3
kubectl scale --curr­ent­-re­pli­cas=2 --repl­icas=3 deploy­men­t/mysql
Scale multiple replic­ation contro­llers
kubectl scale --repl­icas=5 rc/foo rc/bar rc/baz
 

Deleting Resources

Delete a pod using the type and name specified in pod.json
kubectl delete -f ./pod.json
Delete pods and services with same names "­baz­" and "­foo­"
kubectl delete pod,se­rvice baz foo
Delete pods and services with label name=m­yLabel
kubectl delete pods,s­ervices -l name=m­yLabel
Delete all pods and services in namespace my-ns
kubectl -n my-ns delete po,svc --all

Intera­cting with running Pods

dump pod logs (stdout)
kubectl logs my-pod
dump pod container logs (stdout, multi-­con­tainer case)
kubectl logs my-pod -c my-con­tainer
stream pod logs (stdout)
kubectl logs -f my-pod
Attach to Running Container
kubectl attach my-pod -i
Forward port 6000 of Pod to your to 5000 on your local machine
kubectl port-f­orward my-pod 5000:6000
Run command in existing pod (1 container case)
kubectl exec my-pod -- ls /
Show metrics for a given pod and its containers
kubectl top pod POD_NAME --cont­ainers