All Cheatsheets

Kubernetes Cheatsheet

kubectl commands for pods, deployments, services, config, RBAC, and cluster management.

7 sections67 commandsClick any row to copy

Cluster & Context

kubectl version --short
kubectl cluster-info
kubectl get nodes
kubectl get nodes -o wide
kubectl config get-contexts
kubectl config use-context my-cluster
kubectl config current-context
kubectl config set-context --current --namespace=dev

Client and server version

Cluster API server and DNS endpoints

List all nodes

Nodes with IP, OS, kernel info

List all kubeconfig contexts

Switch active context

Show current context name

Set default namespace for current context

Pods

kubectl get pods
kubectl get pods -n kube-system
kubectl get pods -A
kubectl get pods -o wide
kubectl get pods -l app=nginx
kubectl describe pod mypod
kubectl logs mypod
kubectl logs -f mypod
kubectl logs mypod -c mycontainer
kubectl logs mypod --previous
kubectl exec -it mypod -- bash
kubectl exec mypod -- cat /etc/hosts
kubectl delete pod mypod
kubectl delete pod mypod --force --grace-period=0
kubectl get pod mypod -o yaml

List pods in default namespace

List pods in specific namespace

List pods across all namespaces

Pods with node and IP info

Filter pods by label

Full pod details, events, conditions

View pod logs

Follow logs in real time

Logs from specific container in pod

Logs from previous (crashed) container

Interactive shell inside pod

Run one-off command in pod

Delete pod (will be recreated by Deployment)

Force delete stuck pod

Get full pod YAML manifest

Deployments

kubectl get deployments
kubectl create deployment nginx --image=nginx:1.25
kubectl scale deployment nginx --replicas=3
kubectl set image deployment/nginx nginx=nginx:1.26
kubectl rollout status deployment/nginx
kubectl rollout history deployment/nginx
kubectl rollout undo deployment/nginx
kubectl rollout undo deployment/nginx --to-revision=2
kubectl rollout pause deployment/nginx
kubectl rollout resume deployment/nginx
kubectl delete deployment nginx

List all deployments

Create deployment imperatively

Scale deployment to 3 replicas

Update container image (rolling update)

Watch rollout progress

Show rollout revision history

Rollback to previous revision

Rollback to specific revision

Pause rollout mid-way

Resume paused rollout

Delete deployment and its pods

Services & Networking

kubectl get services
kubectl expose deployment nginx --port=80 --type=ClusterIP
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl expose deployment nginx --port=80 --type=LoadBalancer
kubectl port-forward svc/nginx 8080:80
kubectl port-forward pod/mypod 5000:5000
kubectl get ingress -A
kubectl get endpoints nginx

List all services

Expose deployment as ClusterIP service

Expose as NodePort (accessible outside cluster)

Expose via cloud load balancer

Forward local port 8080 to service port 80

Port forward directly to pod

List all ingress rules

Show which pods a service routes to

ConfigMaps & Secrets

kubectl get configmaps
kubectl create configmap app-config --from-file=config.env
kubectl create configmap app-config --from-literal=DB_HOST=localhost
kubectl describe configmap app-config
kubectl get secrets
kubectl create secret generic db-secret --from-literal=password=S3cr3t!
kubectl create secret docker-registry regcred --docker-server=ghcr.io --docker-username=user --docker-password=TOKEN
kubectl get secret db-secret -o jsonpath='{.data.password}' | base64 -d

List all configmaps

Create configmap from file

Create configmap from literal key=value

View configmap contents

List all secrets

Create opaque secret

Create image pull secret

Decode and read secret value

Namespaces & RBAC

kubectl get namespaces
kubectl create namespace dev
kubectl delete namespace dev
kubectl get serviceaccounts -n dev
kubectl get roles,rolebindings -n dev
kubectl get clusterroles,clusterrolebindings
kubectl auth can-i create pods --as=system:serviceaccount:dev:mysa

List all namespaces

Create namespace

Delete namespace and everything in it

List service accounts in namespace

List RBAC roles in namespace

List cluster-wide RBAC

Check if service account has permission

Apply & Debug

kubectl apply -f manifest.yaml
kubectl apply -f ./k8s/
kubectl delete -f manifest.yaml
kubectl diff -f manifest.yaml
kubectl get events -n dev --sort-by=.lastTimestamp
kubectl top nodes
kubectl top pods -A
kubectl debug pod/mypod --image=busybox --copy-to=debug-pod
kubectl run tmp --image=busybox --rm -it -- sh
kubectl get all -n dev

Apply/update resource from YAML

Apply all YAMLs in directory

Delete resources defined in YAML

Preview changes before applying

Recent events, sorted by time

Node CPU and memory usage

Pod CPU and memory usage across all namespaces

Create debug copy of pod with tools

Quick throwaway debug pod

Get all resources in a namespace