Kubernetes Cheat Sheet
Kubernetes Cheat Sheet
What is Kubernetes?
Kubernetes is a platform for managing containerized Services Roles
workloads. Kubernetes orchestrates computing, $ kubectl get svc $ kubectl get roles --al $
networking and storage to provide a seamless portability l -namespaces
$ kubectl describe svc kubectl get roles --al
across infrastructure providers. l-namespaces -o yaml
$ kubectl get svc -o wide
$ kubectl get svc -o yaml
Secrets
$ kubectl get svc --show-labels
Viewing Resource Information $ kubectl get secrets $ kubectl get secrets --
all-namespaces $ kubectl get secrets -o yaml
Nodes
$ kubectl get no DaemonSets ConfigMaps
$ kubectl get no -o wide $ kubectl get ds $ kubectl get cm $ kubectl get cm --al $
$ kubectl describe no $ kubectl get ds --all-namespaces kubectl get cm --al
$ kubectl get no -o yaml $ kubectl describe ds [daemonset_name] -n
[ namespace_name]
$ kubectl get node --selector=[label_name]
$ kubectl get ds [ds_name] -n [ns_name] -o l -namespaces
$ kubectl get nodes -o
j sonpat h=' {. i t ems[ *] . st at us. addresses yaml l-namespaces -o yaml
[ ?(@. t ype=="Ext ernal I P")] . address}'
$ kubectl top node [node_name] Events Ing re s s
$ kubectl get ing
Pods $ kubectl get events
$ kubectl get ing --al
$ kubectl get po $ kubectl get events -n kube-system l -namespaces
$ kubectl get po -o wide $ kubectl get events -w
$ kubectl describe po PersistentVolume
$ kubectl get po --show-labels $ kubectl get pv
Logs
$ kubectl get po -l app=nginx $ kubectl describe pv
$ kubectl logs [pod_name]
$ kubectl get po -o yaml
$ kubectl logs --since=1h [pod_name]
$ kubectl get pod [pod_name] -o yaml
--export
$ kubectl logs --tail=20 [pod_name] PersistentVolumeClaim
$ kubectl get pod [pod_name] -o yaml $ kubectl logs -f -c [container_name] $ kubectl get pvc
[ pod_name]
--export > nameoffile.yaml $ kubectl describe pvc
$ kubectl logs [pod_name] > pod.log
$ kubectl get pods --field-selector
st at us. phase=Runni ng Service Accounts
Nam esp ac es $ kubectl get sa
$ kubectl get ns $ kubectl get sa -o yaml
$ kubectl get ns -o yaml $ kubectl get serviceaccounts default -o
$ kubectl describe ns yaml > ./sa.yaml
$ kubectl replace serviceaccount default -f
. / sa. yaml
Kubernetes Cheat Dep loy m ent s/ Nam esp ac es
$ kubectl edit deploy [deploy_name] $ kubectl
Creating a Deployment
$ kubectl create -f [name_of_file] $ kubectl apply -f
Adding Resources
Cordon/Uncordon Cluster Info
$ kubectl cordon [node_name] $ kubectl
Creating a Pod $ kubectl config $ kubectl cluster-info
$ kubectl create -f [name_of_file] $ kubectl apply -f
uncordon [node_name] $ kubectl get componentstatuses
[name_of_file] $ kubectl run [pod_name] --
Dra in image=nginx
--rest art =Never
$ kubectl drain [node_name]
$ kubectl run [pod_name]
--generator=run-pod/v1 --image=nginx
$ kubectl run [pod_name] --image=nginx
Nodes/Pods --rest art =Never
$ kubectl delete node [node_name] $ Creating a Service
kubectl delete pod [pod_name] $ kubectl $ kubectl create svc nodeport [svc_name] --t cp=8080:
edit node [node_name] $ kubectl edit pod 80
[pod_name]