This is a small kubectl Cheat Sheet with the list of commands and settings I use, almost on a daily basis, when working with kubernetes.
Get version and cluster information#
Get kubectl version#
kubectl --versionGet cluster information#
kubectl cluster-infoCheck cluster nodes#
kubectl get nodesGet running services#
kubectl get services -w --all-namespacesContext#
List all available contexts#
kubectl config get-contextsGet current context#
kubectl config current-contextChange the context#
kubectl config use-context [context name]Deployment#
Deploy#
kubectl apply -f [yaml definition file]Get deployment definition#
kubectl get deployment [deployment name] -o yamlUpdate the image of a deployment#
kubectl set image deployment/[deployment name] [container name]=[image tag]Set autoscale for a deployment#
kubectl autoscale deployment [deployment name] --min=2 --max=5 --cpu-percent=80Delete a deployment#
kubectl delete -f [yaml definition file]Get secret definition#
kubectl get secret [secret name] -o yamlForce delete a pod#
kubectl delete pod [pod name] --grace-period=0 --forceLogs#
Read a pod’s log#
kubectl logs [pod name] -n [namespace name]Misc#
Install kubernetes dashboard#
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yamlHope it helps!
