Kubectl CheatSheet v2
Kubectl CheatSheet v2
C H E AT S H E E T
( H T T P S : // C H E AT S H E E T. D E N N Y Z
us c e s e s to ap y be p a t
January 1, 2019
(https://github.com/dennyzhang/cheatsheet-kubernetes-A4)
(https://www.linkedin.com/in/dennyzhang001)
(https://github.com/dennyzhang)
(https://www.dennyzhang.com/slack)
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 1/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
File me Issues (https://github.com/dennyzhang/cheatsheet.dennyzhang.com/issues) or star this repo
(https://github.com/dennyzhang/cheatsheet.dennyzhang.com).
Name Command
Run curl test temporarily kubectl run --rm mytest --image=yauritux/busybox-curl -it
Run wget test temporarily kubectl run --rm mytest --image=busybox -it
Run nginx deployment with 2 replicas kubectl run my-nginx --image=nginx --replicas=2 --port=80
Run nginx deployment and expose it kubectl run my-nginx --image=nginx --port=80 --expose
Get resources with json output kubectl get pods --all-namespaces -o json
Validate yaml le with dry run kubectl create --dry-run --validate -f pod-dummy.yaml
Start a temporary pod for testing kubectl run --rm -i -t --image=alpine test-$RANDOM -- sh
Get system conf via con gmap kubectl -n kube-system get cm kubeadm-config -o yaml
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 2/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
Name Command
list-all-images.sh (https://github.com/dennyzhang/cheatsheet-
List all container images
kubernetes-A4/blob/master/list-all-images.sh#L14-L17)
skip-tls-verify.md (https://github.com/dennyzhang/cheatsheet-
kubecon g skip tls veri cation
kubernetes-A4/blob/master/skip-tls-verify.md)
minikube cheatsheet
(https://cheatsheet.dennyzhang.com/cheatsheet-minikube-A4),
docker cheatsheet
Reference
(https://cheatsheet.dennyzhang.com/cheatsheet-docker-A4),
OpenShift CheatSheet
(https://cheatsheet.dennyzhang.com/cheatsheet-openshift-A4)
Name Command
Get resource usage for a given pod kubectl top <podname> --containers
List resource utilization for all containers kubectl top pod --all-namespaces --containers=true
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 3/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
Name Command
Delete state fulset only (not pods) kubectl delete sts/<stateful_set_name> --cascade=false
(https://cheatsheet.dennyzhang.com)
Name Comment
Env /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
1.5 POD
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 4/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
Name Command
List pods with more info kubectl get pod -o wide , kubectl get pod/<pod-name> -o yaml
kubectl run command kubectl exec -it -n “$ns” “$podname” – sh -c “echo $msg >>/dev/err.log”
-o=’custom-
List pods and containers
columns=PODS:.metadata.name,CONTAINERS:.spec.containers[*].name’
Name Command
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 5/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
Name Command
online rolling
kubectl rollout app-v1 app-v2 --image=img:v2
upgrade
Check update
kubectl rollout status deployment/nginx-app
status
Check update
kubectl rollout history deployment/nginx-app
history
Rollback to
previous kubectl rollout undo deployment/nginx-deployment
version
(https://cheatsheet.dennyzhang.com)
Name Command
Customize resource
kubectl set resources deployment nginx -c=nginx --limits=cpu=200m
de nition
Customize resource
kubectl set resources deployment nginx -c=nginx --limits=memory=512Mi
de nition
1.9 SERVICE
Name Command
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 6/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
Name Command
Get service cluster port kubectl get service nginx-service -o go-template='{{(index .spec.ports 0).port}}’
Expose deployment as lb
kubectl expose deployment/my-app --type=LoadBalancer --name=my-service
service
Expose service as lb
kubectl expose service/wordpress-1-svc --type=LoadBalancer --name=ns1
service
1.10 SECRETS
Name Command
Generate
echo -n 'mypasswd' , then redirect to base64 --decode
secret
Get a speci c
eld of a kubectl get secret denny-cluster-kubecon g -o jsonpath=”{.data.value}”
secret
Create secret
kubectl create secret generic db-user-pass –from- le=./username.txt
from cfg le
1.11 STATEFULSET
Name Command
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 7/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
Name Command
Name Command
Name Command
Name Command
Name Command
List authenticated
kubectl config get-contexts , ~/.kube/config
contexts
Set namespace
kubectl config set-context <context_name> --namespace=<ns_name>
preference
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 8/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
Name Command
1.16 NETWORK
Name Command
1.17 PATCH
Name Summary
Patch service to loadbalancer kubectl patch svc $svc_name -p '{"spec": {"type": "LoadBalancer"}}'
1.18 EXTENSTIONS
Name Summary
(https://cheatsheet.dennyzhang.com)
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 9/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
1.19.1 SERVICES ON MASTER NODES
Name Summary
kube-apiserver
exposes the Kubernetes API from master
(https://github.com/kubernetes/kubernetes/tree/master/cmd/kube-
nodes
apiserver)
etcd (https://coreos.com/etcd/) reliable data store for all k8s cluster data
kube-scheduler
(https://github.com/kubernetes/kubernetes/tree/master/cmd/kube- schedule pods to run on selected nodes
scheduler)
Name Summary
kube-proxy
(https://github.com/kubernetes/kubernetes/tree/master/cmd/kube- perform connection forwarding
proxy)
Name Summary
Cluster-level Logging save container logs to a central log store with search/browsing interface
1.19.4 TOOLS
Name Summary
kubectl
the command line util to talk to k8s cluster
(https://github.com/kubernetes/kubernetes/tree/master/cmd/kubectl)
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 10/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
Name Summary
kubeadm
the command to bootstrap the cluster
(https://github.com/kubernetes/kubernetes/tree/master/cmd/kubeadm)
kubefed (https://kubernetes.io/docs/reference/setup-
the command line to control a Kubernetes Cluster Federation
tools/kubefed/kubefed/)
https://kubernetes.io/docs/reference/kubectl/cheatsheet/ (https://kubernetes.io/docs/reference/kubectl/cheatsheet/)
https://codefresh.io/kubernetes-guides/kubernetes-cheat-sheet/ (https://codefresh.io/kubernetes-guides/kubernetes-cheat-
sheet/)
(https://cheatsheet.dennyzhang.com)
(https://cheatsheet.dennyzhang.com)
(https://www.linkedin.com/in/dennyzhang001)
(https://github.com/dennyzhang)
(https://www.dennyzhang.com/slack)
LEAVE A REPLY
Your email address will not be published. Required elds are marked *
NAME*
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 11/12
17/04/2020 Kubectl Kubernetes Free CheatSheet – CheatSheet
EMAIL ADDRESS*
WEBSITE
COMMENT
Save my name, email, and website in this browser for the next time I comment.
POST COMMENT
https://cheatsheet.dennyzhang.com/cheatsheet-kubernetes-a4 12/12