Kubernetes Cheat Sheet (With Explanations)

DevOpsLaunchpadDevOpsLaunchpad
4 min read


A one-stop guide covering Pods → ConfigMaps/Secrets → Storage → Networking → Namespaces → RBAC → Scheduling


1️⃣ Basic Commands

CommandExplanation
kubectl versionCheck client & server Kubernetes version
kubectl cluster-infoShow cluster master & services info
kubectl get nodesList all nodes in cluster
kubectl get pods -AList all pods across namespaces
kubectl describe pod <pod-name>Show detailed info about a pod

2️⃣ Pods & Deployments

CommandExplanation
kubectl run nginx --image=nginxCreate a pod with Nginx image
kubectl create deployment myapp --image=nginxCreate a Deployment
kubectl scale deployment myapp --replicas=3Scale deployment to 3 pods
kubectl rollout status deployment/myappCheck rollout status
kubectl rollout undo deployment/myappRollback last deployment

3️⃣ ConfigMaps & Secrets

CommandExplanation
kubectl create configmap app-config --from-literal=APP_MODE=prodCreate ConfigMap
kubectl get configmap app-config -o yamlView ConfigMap
kubectl create secret generic db-secret --from-literal=USER=admin --from-literal=PASS=1234Create Secret
kubectl get secret db-secret -o yamlView Secret (base64 encoded)
`echo "YWRtaW4="base64 -d`Decode Secret value

4️⃣ Storage (PV & PVC)

CommandExplanation
kubectl get pvList Persistent Volumes
kubectl get pvcList Persistent Volume Claims
kubectl describe pvc myclaimShow PVC details
kubectl delete pvc myclaimDelete PVC
kubectl apply -f pvc.yamlApply PVC manifest

5️⃣ Networking (Services & Ingress)

CommandExplanation
kubectl expose deployment myapp --port=80 --type=NodePortExpose Deployment as NodePort
kubectl get svcList all services
kubectl describe svc myappShow service details
kubectl apply -f ingress.yamlApply Ingress rule
kubectl get ingressList ingress resources

6️⃣ Namespaces

CommandExplanation
kubectl get nsList all namespaces
kubectl create ns devCreate new namespace
kubectl config set-context --current --namespace=devSwitch default namespace
kubectl get pods -n kube-systemList pods in kube-system namespace

7️⃣ RBAC (Role-Based Access Control)

CommandExplanation
kubectl create role pod-reader --verb=get --verb=list --resource=pods -n devCreate role to read pods
kubectl create rolebinding read-pods --role=pod-reader --user=alice -n devBind role to user
kubectl get roles -n devList roles
kubectl describe rolebinding read-pods -n devShow rolebinding details

8️⃣ Scheduling (Affinity, Taints & Tolerations)

CommandExplanation
kubectl describe node <node-name>View node labels & taints
kubectl taint nodes <node> key=value:NoScheduleAdd taint to node
kubectl taint nodes <node> key=value:NoSchedule-Remove taint
kubectl label nodes <node> disktype=ssdAdd label to node
kubectl get pods --field-selector spec.nodeName=<node>Check pods scheduled on node

9️⃣ Monitoring & Debugging

CommandExplanation
kubectl logs <pod>View logs of a pod
kubectl logs -f <pod>Stream logs
kubectl exec -it <pod> -- /bin/shEnter pod shell
kubectl top podsShow resource usage (requires metrics-server)
kubectl get eventsShow cluster events

🔟 YAML Quick Reference

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: myapp
    image: nginx
    ports:
    - containerPort: 80

0
Subscribe to my newsletter

Read articles from DevOpsLaunchpad directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

DevOpsLaunchpad
DevOpsLaunchpad