kubectl cheatsheet

https://kubernetes.io/docs/reference/kubectl/cheatsheet/

clusters and namespaces

list clusters

kubectl config get-contexts -o=name

show current cluster

kubectl config current-context

switch cluster

kubectl config use-context my-cluster-name

change default namespace

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

deployments

restart deployment

kubectl rollout restart deployment acme

rollback deployment

kubectl rollout undo deployment acme

update image

# kubectl set image deployment/[DEPLOYMENT_NAME] [CONTAINER_NAME]=[IMAGE]:[TAG]
kubectl set image deployment/acme acme=gcr.io/majestic-123/foo:2.0.3-master

change env variable

kubectl set env deployment/acme MY_VAR=foo

change resources

kubectl set resources deployment -l app=acme --limits memory=100Mi

manual scale

kubectl scale deployment foo --replicas=2

other

run ubuntu

kubectl run my-shell --rm -it --image ubuntu -- bash