Tools: Report: Kubernetes Cheatsheet: Daily Commands Every Developer Actually Uses

Tools: Report: Kubernetes Cheatsheet: Daily Commands Every Developer Actually Uses

โšก Cluster State โ€” Is Everything OK?

๐Ÿƒ Pods โ€” Daily Inspection

๐Ÿ“‹ Logs โ€” What Is It Saying?

๐Ÿ” Debugging โ€” Getting Inside

๐Ÿš€ Deployments โ€” Rolling Updates and Rollbacks

๐Ÿ—‚๏ธ Namespaces โ€” Context Switching

๐Ÿ”‘ Secrets and ConfigMaps

๐ŸŒ Services and Networking

โš™๏ธ Apply, Diff, Delete

๐Ÿท๏ธ Labels and Selectors โ€” Finding Things

๐Ÿ›ก๏ธ RBAC โ€” Quick Check

๐Ÿ”„ Jobs and CronJobs

๐Ÿงน Cleanup โ€” Housekeeping

โšก Essential Aliases

๐Ÿ”ง kubectl Plugins Worth Installing

๐Ÿ†˜ The 5-Minute Debugging Checklist What this is: The 20% of Kubernetes that covers 80% of daily work. Cluster state, pod management, debugging, deployments, secrets, logs, resource inspection โ€” organized by task, not by resource type. Pod status quick reference: Add to ~/.bashrc or ~/.zshrc: After adding: source ~/.bashrc Install krew (plugin manager) first: Then install plugins: Pod not starting or crashing? Go in order: If describe shows OOMKilled โ†’ increase memory limits.

If ImagePullBackOff โ†’ check image name and registry credentials.If Pending โ†’ check node capacity with kubectl describe node.

If CrashLoopBackOff โ†’ check logs with --previous flag. April 2026. Tested against Kubernetes 1.32. Commands work on any managed cluster (EKS, GKE, AKS) and local setups (minikube, k3s, kind). Templates let you quickly answer FAQs or store snippets for re-use. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

# Overall health check -weight: 500;">kubectl get nodes -weight: 500;">kubectl get nodes -o wide # with IPs and OS info # All resources across all namespaces -weight: 500;">kubectl get all -A # What's failing right now -weight: 500;">kubectl get pods -A | grep -v Running | grep -v Completed # Cluster events (recent activity, errors) -weight: 500;">kubectl get events --sort-by='.lastTimestamp' -weight: 500;">kubectl get events -A --sort-by='.lastTimestamp' | tail -30 # Resource usage (requires metrics-server) -weight: 500;">kubectl top nodes -weight: 500;">kubectl top pods -A -weight: 500;">kubectl top pods --sort-by=cpu -weight: 500;">kubectl top pods --sort-by=memory # Overall health check -weight: 500;">kubectl get nodes -weight: 500;">kubectl get nodes -o wide # with IPs and OS info # All resources across all namespaces -weight: 500;">kubectl get all -A # What's failing right now -weight: 500;">kubectl get pods -A | grep -v Running | grep -v Completed # Cluster events (recent activity, errors) -weight: 500;">kubectl get events --sort-by='.lastTimestamp' -weight: 500;">kubectl get events -A --sort-by='.lastTimestamp' | tail -30 # Resource usage (requires metrics-server) -weight: 500;">kubectl top nodes -weight: 500;">kubectl top pods -A -weight: 500;">kubectl top pods --sort-by=cpu -weight: 500;">kubectl top pods --sort-by=memory # Overall health check -weight: 500;">kubectl get nodes -weight: 500;">kubectl get nodes -o wide # with IPs and OS info # All resources across all namespaces -weight: 500;">kubectl get all -A # What's failing right now -weight: 500;">kubectl get pods -A | grep -v Running | grep -v Completed # Cluster events (recent activity, errors) -weight: 500;">kubectl get events --sort-by='.lastTimestamp' -weight: 500;">kubectl get events -A --sort-by='.lastTimestamp' | tail -30 # Resource usage (requires metrics-server) -weight: 500;">kubectl top nodes -weight: 500;">kubectl top pods -A -weight: 500;">kubectl top pods --sort-by=cpu -weight: 500;">kubectl top pods --sort-by=memory # List pods -weight: 500;">kubectl get pods # current namespace -weight: 500;">kubectl get pods -n <namespace> # specific namespace -weight: 500;">kubectl get pods -A # all namespaces -weight: 500;">kubectl get pods -o wide # with node placement # Watch pods in real time -weight: 500;">kubectl get pods -w -weight: 500;">kubectl get pods -w -n <namespace> # Pod details (why is it stuck?) -weight: 500;">kubectl describe pod <pod-name> -weight: 500;">kubectl describe pod <pod-name> -n <namespace> # Get pod YAML -weight: 500;">kubectl get pod <pod-name> -o yaml # Delete a stuck pod -weight: 500;">kubectl delete pod <pod-name> -weight: 500;">kubectl delete pod <pod-name> --force --grace-period=0 # force kill # List pods -weight: 500;">kubectl get pods # current namespace -weight: 500;">kubectl get pods -n <namespace> # specific namespace -weight: 500;">kubectl get pods -A # all namespaces -weight: 500;">kubectl get pods -o wide # with node placement # Watch pods in real time -weight: 500;">kubectl get pods -w -weight: 500;">kubectl get pods -w -n <namespace> # Pod details (why is it stuck?) -weight: 500;">kubectl describe pod <pod-name> -weight: 500;">kubectl describe pod <pod-name> -n <namespace> # Get pod YAML -weight: 500;">kubectl get pod <pod-name> -o yaml # Delete a stuck pod -weight: 500;">kubectl delete pod <pod-name> -weight: 500;">kubectl delete pod <pod-name> --force --grace-period=0 # force kill # List pods -weight: 500;">kubectl get pods # current namespace -weight: 500;">kubectl get pods -n <namespace> # specific namespace -weight: 500;">kubectl get pods -A # all namespaces -weight: 500;">kubectl get pods -o wide # with node placement # Watch pods in real time -weight: 500;">kubectl get pods -w -weight: 500;">kubectl get pods -w -n <namespace> # Pod details (why is it stuck?) -weight: 500;">kubectl describe pod <pod-name> -weight: 500;">kubectl describe pod <pod-name> -n <namespace> # Get pod YAML -weight: 500;">kubectl get pod <pod-name> -o yaml # Delete a stuck pod -weight: 500;">kubectl delete pod <pod-name> -weight: 500;">kubectl delete pod <pod-name> --force --grace-period=0 # force kill # Basic logs -weight: 500;">kubectl logs <pod-name> -weight: 500;">kubectl logs <pod-name> -n <namespace> # Follow live -weight: 500;">kubectl logs -f <pod-name> # Last N lines -weight: 500;">kubectl logs <pod-name> --tail=100 # Logs since time -weight: 500;">kubectl logs <pod-name> --since=1h -weight: 500;">kubectl logs <pod-name> --since=30m # Multi-container pod โ€” specify container -weight: 500;">kubectl logs <pod-name> -c <container-name> # Previous container (after crash) -weight: 500;">kubectl logs <pod-name> --previous -weight: 500;">kubectl logs <pod-name> -c <container-name> --previous # All pods in a deployment at once -weight: 500;">kubectl logs -l app=<label-value> --all-containers=true -weight: 500;">kubectl logs -l app=<label-value> -f --tail=50 # Basic logs -weight: 500;">kubectl logs <pod-name> -weight: 500;">kubectl logs <pod-name> -n <namespace> # Follow live -weight: 500;">kubectl logs -f <pod-name> # Last N lines -weight: 500;">kubectl logs <pod-name> --tail=100 # Logs since time -weight: 500;">kubectl logs <pod-name> --since=1h -weight: 500;">kubectl logs <pod-name> --since=30m # Multi-container pod โ€” specify container -weight: 500;">kubectl logs <pod-name> -c <container-name> # Previous container (after crash) -weight: 500;">kubectl logs <pod-name> --previous -weight: 500;">kubectl logs <pod-name> -c <container-name> --previous # All pods in a deployment at once -weight: 500;">kubectl logs -l app=<label-value> --all-containers=true -weight: 500;">kubectl logs -l app=<label-value> -f --tail=50 # Basic logs -weight: 500;">kubectl logs <pod-name> -weight: 500;">kubectl logs <pod-name> -n <namespace> # Follow live -weight: 500;">kubectl logs -f <pod-name> # Last N lines -weight: 500;">kubectl logs <pod-name> --tail=100 # Logs since time -weight: 500;">kubectl logs <pod-name> --since=1h -weight: 500;">kubectl logs <pod-name> --since=30m # Multi-container pod โ€” specify container -weight: 500;">kubectl logs <pod-name> -c <container-name> # Previous container (after crash) -weight: 500;">kubectl logs <pod-name> --previous -weight: 500;">kubectl logs <pod-name> -c <container-name> --previous # All pods in a deployment at once -weight: 500;">kubectl logs -l app=<label-value> --all-containers=true -weight: 500;">kubectl logs -l app=<label-value> -f --tail=50 # Shell into a running pod -weight: 500;">kubectl exec -it <pod-name> -- /bin/bash -weight: 500;">kubectl exec -it <pod-name> -- /bin/sh # if bash not available -weight: 500;">kubectl exec -it <pod-name> -c <container> -- /bin/sh # Run a one-off command -weight: 500;">kubectl exec <pod-name> -- env -weight: 500;">kubectl exec <pod-name> -- cat /etc/hosts -weight: 500;">kubectl exec <pod-name> -- ls /app # Debug with a temporary pod (when your pod has no shell) -weight: 500;">kubectl run debug --image=busybox -it --rm -- /bin/sh -weight: 500;">kubectl run debug --image=nicolaka/netshoot -it --rm -- /bin/bash # Debug a specific node -weight: 500;">kubectl debug node/<node-name> -it --image=ubuntu # Copy files to/from pod -weight: 500;">kubectl cp <pod-name>:/path/to/file ./local-file -weight: 500;">kubectl cp ./local-file <pod-name>:/path/to/file # Shell into a running pod -weight: 500;">kubectl exec -it <pod-name> -- /bin/bash -weight: 500;">kubectl exec -it <pod-name> -- /bin/sh # if bash not available -weight: 500;">kubectl exec -it <pod-name> -c <container> -- /bin/sh # Run a one-off command -weight: 500;">kubectl exec <pod-name> -- env -weight: 500;">kubectl exec <pod-name> -- cat /etc/hosts -weight: 500;">kubectl exec <pod-name> -- ls /app # Debug with a temporary pod (when your pod has no shell) -weight: 500;">kubectl run debug --image=busybox -it --rm -- /bin/sh -weight: 500;">kubectl run debug --image=nicolaka/netshoot -it --rm -- /bin/bash # Debug a specific node -weight: 500;">kubectl debug node/<node-name> -it --image=ubuntu # Copy files to/from pod -weight: 500;">kubectl cp <pod-name>:/path/to/file ./local-file -weight: 500;">kubectl cp ./local-file <pod-name>:/path/to/file # Shell into a running pod -weight: 500;">kubectl exec -it <pod-name> -- /bin/bash -weight: 500;">kubectl exec -it <pod-name> -- /bin/sh # if bash not available -weight: 500;">kubectl exec -it <pod-name> -c <container> -- /bin/sh # Run a one-off command -weight: 500;">kubectl exec <pod-name> -- env -weight: 500;">kubectl exec <pod-name> -- cat /etc/hosts -weight: 500;">kubectl exec <pod-name> -- ls /app # Debug with a temporary pod (when your pod has no shell) -weight: 500;">kubectl run debug --image=busybox -it --rm -- /bin/sh -weight: 500;">kubectl run debug --image=nicolaka/netshoot -it --rm -- /bin/bash # Debug a specific node -weight: 500;">kubectl debug node/<node-name> -it --image=ubuntu # Copy files to/from pod -weight: 500;">kubectl cp <pod-name>:/path/to/file ./local-file -weight: 500;">kubectl cp ./local-file <pod-name>:/path/to/file # List deployments -weight: 500;">kubectl get deployments -weight: 500;">kubectl get deploy -n <namespace> # Deployment -weight: 500;">status -weight: 500;">kubectl rollout -weight: 500;">status deployment/<name> # Rollout history -weight: 500;">kubectl rollout history deployment/<name> # Update image -weight: 500;">kubectl set image deployment/<name> <container>=<image>:<tag> -weight: 500;">kubectl set image deployment/api api=myregistry/api:v2.1.0 # Scale -weight: 500;">kubectl scale deployment/<name> --replicas=5 # Rollback -weight: 500;">kubectl rollout undo deployment/<name> # to previous -weight: 500;">kubectl rollout undo deployment/<name> --to-revision=2 # to specific # Pause/resume rollout -weight: 500;">kubectl rollout pause deployment/<name> -weight: 500;">kubectl rollout resume deployment/<name> # Restart all pods (rolling -weight: 500;">restart, zero downtime) -weight: 500;">kubectl rollout -weight: 500;">restart deployment/<name> # Force immediate -weight: 500;">update (re-pulls image, destroys and recreates) -weight: 500;">kubectl rollout -weight: 500;">restart deployment/<name> # List deployments -weight: 500;">kubectl get deployments -weight: 500;">kubectl get deploy -n <namespace> # Deployment -weight: 500;">status -weight: 500;">kubectl rollout -weight: 500;">status deployment/<name> # Rollout history -weight: 500;">kubectl rollout history deployment/<name> # Update image -weight: 500;">kubectl set image deployment/<name> <container>=<image>:<tag> -weight: 500;">kubectl set image deployment/api api=myregistry/api:v2.1.0 # Scale -weight: 500;">kubectl scale deployment/<name> --replicas=5 # Rollback -weight: 500;">kubectl rollout undo deployment/<name> # to previous -weight: 500;">kubectl rollout undo deployment/<name> --to-revision=2 # to specific # Pause/resume rollout -weight: 500;">kubectl rollout pause deployment/<name> -weight: 500;">kubectl rollout resume deployment/<name> # Restart all pods (rolling -weight: 500;">restart, zero downtime) -weight: 500;">kubectl rollout -weight: 500;">restart deployment/<name> # Force immediate -weight: 500;">update (re-pulls image, destroys and recreates) -weight: 500;">kubectl rollout -weight: 500;">restart deployment/<name> # List deployments -weight: 500;">kubectl get deployments -weight: 500;">kubectl get deploy -n <namespace> # Deployment -weight: 500;">status -weight: 500;">kubectl rollout -weight: 500;">status deployment/<name> # Rollout history -weight: 500;">kubectl rollout history deployment/<name> # Update image -weight: 500;">kubectl set image deployment/<name> <container>=<image>:<tag> -weight: 500;">kubectl set image deployment/api api=myregistry/api:v2.1.0 # Scale -weight: 500;">kubectl scale deployment/<name> --replicas=5 # Rollback -weight: 500;">kubectl rollout undo deployment/<name> # to previous -weight: 500;">kubectl rollout undo deployment/<name> --to-revision=2 # to specific # Pause/resume rollout -weight: 500;">kubectl rollout pause deployment/<name> -weight: 500;">kubectl rollout resume deployment/<name> # Restart all pods (rolling -weight: 500;">restart, zero downtime) -weight: 500;">kubectl rollout -weight: 500;">restart deployment/<name> # Force immediate -weight: 500;">update (re-pulls image, destroys and recreates) -weight: 500;">kubectl rollout -weight: 500;">restart deployment/<name> # List namespaces -weight: 500;">kubectl get namespaces # Set default namespace for session -weight: 500;">kubectl config set-context --current --namespace=<namespace> # One-off in specific namespace -weight: 500;">kubectl get pods -n kube-system # View current context -weight: 500;">kubectl config current-context -weight: 500;">kubectl config get-contexts # Switch context (cluster) -weight: 500;">kubectl config use-context <context-name> # Useful alias to avoid typing -n constantly alias kns='-weight: 500;">kubectl config set-context --current --namespace' # Usage: kns production # List namespaces -weight: 500;">kubectl get namespaces # Set default namespace for session -weight: 500;">kubectl config set-context --current --namespace=<namespace> # One-off in specific namespace -weight: 500;">kubectl get pods -n kube-system # View current context -weight: 500;">kubectl config current-context -weight: 500;">kubectl config get-contexts # Switch context (cluster) -weight: 500;">kubectl config use-context <context-name> # Useful alias to avoid typing -n constantly alias kns='-weight: 500;">kubectl config set-context --current --namespace' # Usage: kns production # List namespaces -weight: 500;">kubectl get namespaces # Set default namespace for session -weight: 500;">kubectl config set-context --current --namespace=<namespace> # One-off in specific namespace -weight: 500;">kubectl get pods -n kube-system # View current context -weight: 500;">kubectl config current-context -weight: 500;">kubectl config get-contexts # Switch context (cluster) -weight: 500;">kubectl config use-context <context-name> # Useful alias to avoid typing -n constantly alias kns='-weight: 500;">kubectl config set-context --current --namespace' # Usage: kns production # List -weight: 500;">kubectl get secrets -weight: 500;">kubectl get configmaps # View (careful โ€” values are base64) -weight: 500;">kubectl describe secret <name> -weight: 500;">kubectl get secret <name> -o yaml # Decode a specific key -weight: 500;">kubectl get secret <name> -o jsonpath='{.data.<key>}' | base64 -d # Create secret from literal -weight: 500;">kubectl create secret generic <name> \ --from-literal=DB_PASSWORD=mysecret \ --from-literal=API_KEY=abc123 # Create secret from file -weight: 500;">kubectl create secret generic <name> --from-file=./secret.env # Create -weight: 500;">docker registry secret -weight: 500;">kubectl create secret -weight: 500;">docker-registry regcred \ ---weight: 500;">docker-server=registry.example.com \ ---weight: 500;">docker-username=user \ ---weight: 500;">docker-password=pass # Create configmap -weight: 500;">kubectl create configmap <name> --from-literal=ENV=production -weight: 500;">kubectl create configmap <name> --from-file=./config.properties # Edit in place -weight: 500;">kubectl edit secret <name> -weight: 500;">kubectl edit configmap <name> # List -weight: 500;">kubectl get secrets -weight: 500;">kubectl get configmaps # View (careful โ€” values are base64) -weight: 500;">kubectl describe secret <name> -weight: 500;">kubectl get secret <name> -o yaml # Decode a specific key -weight: 500;">kubectl get secret <name> -o jsonpath='{.data.<key>}' | base64 -d # Create secret from literal -weight: 500;">kubectl create secret generic <name> \ --from-literal=DB_PASSWORD=mysecret \ --from-literal=API_KEY=abc123 # Create secret from file -weight: 500;">kubectl create secret generic <name> --from-file=./secret.env # Create -weight: 500;">docker registry secret -weight: 500;">kubectl create secret -weight: 500;">docker-registry regcred \ ---weight: 500;">docker-server=registry.example.com \ ---weight: 500;">docker-username=user \ ---weight: 500;">docker-password=pass # Create configmap -weight: 500;">kubectl create configmap <name> --from-literal=ENV=production -weight: 500;">kubectl create configmap <name> --from-file=./config.properties # Edit in place -weight: 500;">kubectl edit secret <name> -weight: 500;">kubectl edit configmap <name> # List -weight: 500;">kubectl get secrets -weight: 500;">kubectl get configmaps # View (careful โ€” values are base64) -weight: 500;">kubectl describe secret <name> -weight: 500;">kubectl get secret <name> -o yaml # Decode a specific key -weight: 500;">kubectl get secret <name> -o jsonpath='{.data.<key>}' | base64 -d # Create secret from literal -weight: 500;">kubectl create secret generic <name> \ --from-literal=DB_PASSWORD=mysecret \ --from-literal=API_KEY=abc123 # Create secret from file -weight: 500;">kubectl create secret generic <name> --from-file=./secret.env # Create -weight: 500;">docker registry secret -weight: 500;">kubectl create secret -weight: 500;">docker-registry regcred \ ---weight: 500;">docker-server=registry.example.com \ ---weight: 500;">docker-username=user \ ---weight: 500;">docker-password=pass # Create configmap -weight: 500;">kubectl create configmap <name> --from-literal=ENV=production -weight: 500;">kubectl create configmap <name> --from-file=./config.properties # Edit in place -weight: 500;">kubectl edit secret <name> -weight: 500;">kubectl edit configmap <name> # Describe a node (capacity, allocations, events) -weight: 500;">kubectl describe node <node-name> # Check resource requests vs limits across pods -weight: 500;">kubectl get pods -o custom-columns=\ "NAME:.metadata.name,\ CPU_REQ:.spec.containers[*].resources.requests.cpu,\ CPU_LIM:.spec.containers[*].resources.limits.cpu,\ MEM_REQ:.spec.containers[*].resources.requests.memory,\ MEM_LIM:.spec.containers[*].resources.limits.memory" # Find pods without resource limits (danger) -weight: 500;">kubectl get pods -o json | \ jq -r '.items[] | select(.spec.containers[].resources.limits == null) | .metadata.name' # PersistentVolumes and Claims -weight: 500;">kubectl get pv -weight: 500;">kubectl get pvc -weight: 500;">kubectl get pvc -A -weight: 500;">kubectl describe pvc <name> # Describe a node (capacity, allocations, events) -weight: 500;">kubectl describe node <node-name> # Check resource requests vs limits across pods -weight: 500;">kubectl get pods -o custom-columns=\ "NAME:.metadata.name,\ CPU_REQ:.spec.containers[*].resources.requests.cpu,\ CPU_LIM:.spec.containers[*].resources.limits.cpu,\ MEM_REQ:.spec.containers[*].resources.requests.memory,\ MEM_LIM:.spec.containers[*].resources.limits.memory" # Find pods without resource limits (danger) -weight: 500;">kubectl get pods -o json | \ jq -r '.items[] | select(.spec.containers[].resources.limits == null) | .metadata.name' # PersistentVolumes and Claims -weight: 500;">kubectl get pv -weight: 500;">kubectl get pvc -weight: 500;">kubectl get pvc -A -weight: 500;">kubectl describe pvc <name> # Describe a node (capacity, allocations, events) -weight: 500;">kubectl describe node <node-name> # Check resource requests vs limits across pods -weight: 500;">kubectl get pods -o custom-columns=\ "NAME:.metadata.name,\ CPU_REQ:.spec.containers[*].resources.requests.cpu,\ CPU_LIM:.spec.containers[*].resources.limits.cpu,\ MEM_REQ:.spec.containers[*].resources.requests.memory,\ MEM_LIM:.spec.containers[*].resources.limits.memory" # Find pods without resource limits (danger) -weight: 500;">kubectl get pods -o json | \ jq -r '.items[] | select(.spec.containers[].resources.limits == null) | .metadata.name' # PersistentVolumes and Claims -weight: 500;">kubectl get pv -weight: 500;">kubectl get pvc -weight: 500;">kubectl get pvc -A -weight: 500;">kubectl describe pvc <name> # List services -weight: 500;">kubectl get services -weight: 500;">kubectl get svc -A # Describe (check ports, selectors, endpoints) -weight: 500;">kubectl describe svc <name> # Check endpoints (actual pod IPs behind a -weight: 500;">service) -weight: 500;">kubectl get endpoints <-weight: 500;">service-name> # Quick port-forward to test a -weight: 500;">service locally -weight: 500;">kubectl port-forward svc/<-weight: 500;">service-name> 8080:80 -weight: 500;">kubectl port-forward pod/<pod-name> 9000:8080 # Expose a deployment as a -weight: 500;">service -weight: 500;">kubectl expose deployment <name> --port=80 --target-port=8080 --type=ClusterIP # Get Ingress -weight: 500;">kubectl get ingress -A -weight: 500;">kubectl describe ingress <name> # List services -weight: 500;">kubectl get services -weight: 500;">kubectl get svc -A # Describe (check ports, selectors, endpoints) -weight: 500;">kubectl describe svc <name> # Check endpoints (actual pod IPs behind a -weight: 500;">service) -weight: 500;">kubectl get endpoints <-weight: 500;">service-name> # Quick port-forward to test a -weight: 500;">service locally -weight: 500;">kubectl port-forward svc/<-weight: 500;">service-name> 8080:80 -weight: 500;">kubectl port-forward pod/<pod-name> 9000:8080 # Expose a deployment as a -weight: 500;">service -weight: 500;">kubectl expose deployment <name> --port=80 --target-port=8080 --type=ClusterIP # Get Ingress -weight: 500;">kubectl get ingress -A -weight: 500;">kubectl describe ingress <name> # List services -weight: 500;">kubectl get services -weight: 500;">kubectl get svc -A # Describe (check ports, selectors, endpoints) -weight: 500;">kubectl describe svc <name> # Check endpoints (actual pod IPs behind a -weight: 500;">service) -weight: 500;">kubectl get endpoints <-weight: 500;">service-name> # Quick port-forward to test a -weight: 500;">service locally -weight: 500;">kubectl port-forward svc/<-weight: 500;">service-name> 8080:80 -weight: 500;">kubectl port-forward pod/<pod-name> 9000:8080 # Expose a deployment as a -weight: 500;">service -weight: 500;">kubectl expose deployment <name> --port=80 --target-port=8080 --type=ClusterIP # Get Ingress -weight: 500;">kubectl get ingress -A -weight: 500;">kubectl describe ingress <name> # Apply from file -weight: 500;">kubectl apply -f deployment.yaml -weight: 500;">kubectl apply -f ./k8s/ # all files in directory -weight: 500;">kubectl apply -f ./k8s/ -R # recursive # Diff before applying (see what will change) -weight: 500;">kubectl diff -f deployment.yaml # Delete -weight: 500;">kubectl delete -f deployment.yaml -weight: 500;">kubectl delete pod <name> -weight: 500;">kubectl delete deployment <name> -weight: 500;">kubectl delete all -l app=<label> # by label # Dry run (what would happen without doing it) -weight: 500;">kubectl apply -f deployment.yaml --dry-run=client -weight: 500;">kubectl delete pod <name> --dry-run=client # Apply from file -weight: 500;">kubectl apply -f deployment.yaml -weight: 500;">kubectl apply -f ./k8s/ # all files in directory -weight: 500;">kubectl apply -f ./k8s/ -R # recursive # Diff before applying (see what will change) -weight: 500;">kubectl diff -f deployment.yaml # Delete -weight: 500;">kubectl delete -f deployment.yaml -weight: 500;">kubectl delete pod <name> -weight: 500;">kubectl delete deployment <name> -weight: 500;">kubectl delete all -l app=<label> # by label # Dry run (what would happen without doing it) -weight: 500;">kubectl apply -f deployment.yaml --dry-run=client -weight: 500;">kubectl delete pod <name> --dry-run=client # Apply from file -weight: 500;">kubectl apply -f deployment.yaml -weight: 500;">kubectl apply -f ./k8s/ # all files in directory -weight: 500;">kubectl apply -f ./k8s/ -R # recursive # Diff before applying (see what will change) -weight: 500;">kubectl diff -f deployment.yaml # Delete -weight: 500;">kubectl delete -f deployment.yaml -weight: 500;">kubectl delete pod <name> -weight: 500;">kubectl delete deployment <name> -weight: 500;">kubectl delete all -l app=<label> # by label # Dry run (what would happen without doing it) -weight: 500;">kubectl apply -f deployment.yaml --dry-run=client -weight: 500;">kubectl delete pod <name> --dry-run=client # Filter by label -weight: 500;">kubectl get pods -l app=api -weight: 500;">kubectl get pods -l env=production,tier=backend -weight: 500;">kubectl get pods -l 'env in (staging, production)' # Show labels -weight: 500;">kubectl get pods --show-labels # Add label -weight: 500;">kubectl label pod <name> env=production # Remove label -weight: 500;">kubectl label pod <name> env- # Label a node (for scheduling) -weight: 500;">kubectl label node <node-name> disktype=ssd # Filter by label -weight: 500;">kubectl get pods -l app=api -weight: 500;">kubectl get pods -l env=production,tier=backend -weight: 500;">kubectl get pods -l 'env in (staging, production)' # Show labels -weight: 500;">kubectl get pods --show-labels # Add label -weight: 500;">kubectl label pod <name> env=production # Remove label -weight: 500;">kubectl label pod <name> env- # Label a node (for scheduling) -weight: 500;">kubectl label node <node-name> disktype=ssd # Filter by label -weight: 500;">kubectl get pods -l app=api -weight: 500;">kubectl get pods -l env=production,tier=backend -weight: 500;">kubectl get pods -l 'env in (staging, production)' # Show labels -weight: 500;">kubectl get pods --show-labels # Add label -weight: 500;">kubectl label pod <name> env=production # Remove label -weight: 500;">kubectl label pod <name> env- # Label a node (for scheduling) -weight: 500;">kubectl label node <node-name> disktype=ssd # What can I do? -weight: 500;">kubectl auth can-i --list -weight: 500;">kubectl auth can-i create pods -weight: 500;">kubectl auth can-i delete deployments -n production # What can a -weight: 500;">service account do? -weight: 500;">kubectl auth can-i list pods \ --as=system:serviceaccount:<namespace>:<sa-name> # List roles and bindings -weight: 500;">kubectl get roles -A -weight: 500;">kubectl get rolebindings -A -weight: 500;">kubectl get clusterroles | grep -v system: -weight: 500;">kubectl get clusterrolebindings | grep -v system: # What can I do? -weight: 500;">kubectl auth can-i --list -weight: 500;">kubectl auth can-i create pods -weight: 500;">kubectl auth can-i delete deployments -n production # What can a -weight: 500;">service account do? -weight: 500;">kubectl auth can-i list pods \ --as=system:serviceaccount:<namespace>:<sa-name> # List roles and bindings -weight: 500;">kubectl get roles -A -weight: 500;">kubectl get rolebindings -A -weight: 500;">kubectl get clusterroles | grep -v system: -weight: 500;">kubectl get clusterrolebindings | grep -v system: # What can I do? -weight: 500;">kubectl auth can-i --list -weight: 500;">kubectl auth can-i create pods -weight: 500;">kubectl auth can-i delete deployments -n production # What can a -weight: 500;">service account do? -weight: 500;">kubectl auth can-i list pods \ --as=system:serviceaccount:<namespace>:<sa-name> # List roles and bindings -weight: 500;">kubectl get roles -A -weight: 500;">kubectl get rolebindings -A -weight: 500;">kubectl get clusterroles | grep -v system: -weight: 500;">kubectl get clusterrolebindings | grep -v system: # List -weight: 500;">kubectl get jobs -weight: 500;">kubectl get cronjobs # Watch job progress -weight: 500;">kubectl get jobs -w # Trigger a CronJob manually -weight: 500;">kubectl create job --from=cronjob/<name> <job-name> # Check job logs -weight: 500;">kubectl logs job/<job-name> # Delete completed jobs -weight: 500;">kubectl delete jobs --field-selector -weight: 500;">status.successful=1 # List -weight: 500;">kubectl get jobs -weight: 500;">kubectl get cronjobs # Watch job progress -weight: 500;">kubectl get jobs -w # Trigger a CronJob manually -weight: 500;">kubectl create job --from=cronjob/<name> <job-name> # Check job logs -weight: 500;">kubectl logs job/<job-name> # Delete completed jobs -weight: 500;">kubectl delete jobs --field-selector -weight: 500;">status.successful=1 # List -weight: 500;">kubectl get jobs -weight: 500;">kubectl get cronjobs # Watch job progress -weight: 500;">kubectl get jobs -w # Trigger a CronJob manually -weight: 500;">kubectl create job --from=cronjob/<name> <job-name> # Check job logs -weight: 500;">kubectl logs job/<job-name> # Delete completed jobs -weight: 500;">kubectl delete jobs --field-selector -weight: 500;">status.successful=1 # Delete completed pods -weight: 500;">kubectl delete pods --field-selector=-weight: 500;">status.phase=Succeeded -A -weight: 500;">kubectl delete pods --field-selector=-weight: 500;">status.phase=Failed -A # Delete evicted pods -weight: 500;">kubectl get pods -A | grep Evicted | \ awk '{print $2 " -n " $1}' | xargs -L1 -weight: 500;">kubectl delete pod # Remove all in a namespace -weight: 500;">kubectl delete all --all -n <namespace> # Force delete stuck terminating namespace -weight: 500;">kubectl get namespace <name> -o json | \ jq '.spec.finalizers = []' | \ -weight: 500;">kubectl replace --raw /api/v1/namespaces/<name>/finalize -f - # Delete completed pods -weight: 500;">kubectl delete pods --field-selector=-weight: 500;">status.phase=Succeeded -A -weight: 500;">kubectl delete pods --field-selector=-weight: 500;">status.phase=Failed -A # Delete evicted pods -weight: 500;">kubectl get pods -A | grep Evicted | \ awk '{print $2 " -n " $1}' | xargs -L1 -weight: 500;">kubectl delete pod # Remove all in a namespace -weight: 500;">kubectl delete all --all -n <namespace> # Force delete stuck terminating namespace -weight: 500;">kubectl get namespace <name> -o json | \ jq '.spec.finalizers = []' | \ -weight: 500;">kubectl replace --raw /api/v1/namespaces/<name>/finalize -f - # Delete completed pods -weight: 500;">kubectl delete pods --field-selector=-weight: 500;">status.phase=Succeeded -A -weight: 500;">kubectl delete pods --field-selector=-weight: 500;">status.phase=Failed -A # Delete evicted pods -weight: 500;">kubectl get pods -A | grep Evicted | \ awk '{print $2 " -n " $1}' | xargs -L1 -weight: 500;">kubectl delete pod # Remove all in a namespace -weight: 500;">kubectl delete all --all -n <namespace> # Force delete stuck terminating namespace -weight: 500;">kubectl get namespace <name> -o json | \ jq '.spec.finalizers = []' | \ -weight: 500;">kubectl replace --raw /api/v1/namespaces/<name>/finalize -f - alias k='-weight: 500;">kubectl' alias kgp='-weight: 500;">kubectl get pods' alias kgpa='-weight: 500;">kubectl get pods -A' alias kgpw='-weight: 500;">kubectl get pods -w' alias kgs='-weight: 500;">kubectl get services' alias kgd='-weight: 500;">kubectl get deployments' alias kgn='-weight: 500;">kubectl get nodes' alias kd='-weight: 500;">kubectl describe' alias kdp='-weight: 500;">kubectl describe pod' alias kl='-weight: 500;">kubectl logs' alias klf='-weight: 500;">kubectl logs -f' alias ke='-weight: 500;">kubectl exec -it' alias kaf='-weight: 500;">kubectl apply -f' alias kdf='-weight: 500;">kubectl delete -f' alias kns='-weight: 500;">kubectl config set-context --current --namespace' alias kctx='-weight: 500;">kubectl config use-context' alias kctxs='-weight: 500;">kubectl config get-contexts' alias k='-weight: 500;">kubectl' alias kgp='-weight: 500;">kubectl get pods' alias kgpa='-weight: 500;">kubectl get pods -A' alias kgpw='-weight: 500;">kubectl get pods -w' alias kgs='-weight: 500;">kubectl get services' alias kgd='-weight: 500;">kubectl get deployments' alias kgn='-weight: 500;">kubectl get nodes' alias kd='-weight: 500;">kubectl describe' alias kdp='-weight: 500;">kubectl describe pod' alias kl='-weight: 500;">kubectl logs' alias klf='-weight: 500;">kubectl logs -f' alias ke='-weight: 500;">kubectl exec -it' alias kaf='-weight: 500;">kubectl apply -f' alias kdf='-weight: 500;">kubectl delete -f' alias kns='-weight: 500;">kubectl config set-context --current --namespace' alias kctx='-weight: 500;">kubectl config use-context' alias kctxs='-weight: 500;">kubectl config get-contexts' alias k='-weight: 500;">kubectl' alias kgp='-weight: 500;">kubectl get pods' alias kgpa='-weight: 500;">kubectl get pods -A' alias kgpw='-weight: 500;">kubectl get pods -w' alias kgs='-weight: 500;">kubectl get services' alias kgd='-weight: 500;">kubectl get deployments' alias kgn='-weight: 500;">kubectl get nodes' alias kd='-weight: 500;">kubectl describe' alias kdp='-weight: 500;">kubectl describe pod' alias kl='-weight: 500;">kubectl logs' alias klf='-weight: 500;">kubectl logs -f' alias ke='-weight: 500;">kubectl exec -it' alias kaf='-weight: 500;">kubectl apply -f' alias kdf='-weight: 500;">kubectl delete -f' alias kns='-weight: 500;">kubectl config set-context --current --namespace' alias kctx='-weight: 500;">kubectl config use-context' alias kctxs='-weight: 500;">kubectl config get-contexts' ( set -x; cd "$(mktemp -d)" && OS="$(uname | tr '[:upper:]' '[:lower:]')" && ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" && KREW="krew-${OS}_${ARCH}" && -weight: 500;">curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && tar zxvf "${KREW}.tar.gz" && ./"${KREW}" -weight: 500;">install krew ) ( set -x; cd "$(mktemp -d)" && OS="$(uname | tr '[:upper:]' '[:lower:]')" && ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" && KREW="krew-${OS}_${ARCH}" && -weight: 500;">curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && tar zxvf "${KREW}.tar.gz" && ./"${KREW}" -weight: 500;">install krew ) ( set -x; cd "$(mktemp -d)" && OS="$(uname | tr '[:upper:]' '[:lower:]')" && ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" && KREW="krew-${OS}_${ARCH}" && -weight: 500;">curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" && tar zxvf "${KREW}.tar.gz" && ./"${KREW}" -weight: 500;">install krew ) # 1. What state is it in? -weight: 500;">kubectl get pod <name> -o wide # 2. Why? (look at Events section at the bottom) -weight: 500;">kubectl describe pod <name> # 3. What is it saying? -weight: 500;">kubectl logs <name> -weight: 500;">kubectl logs <name> --previous # if already crashed # 4. Can it reach its dependencies? -weight: 500;">kubectl exec -it <name> -- -weight: 500;">curl http://<-weight: 500;">service-name>:<port>/health # 5. What are its resource limits? -weight: 500;">kubectl describe pod <name> | grep -A3 Limits # 6. Check node pressure -weight: 500;">kubectl describe node $(-weight: 500;">kubectl get pod <name> -o jsonpath='{.spec.nodeName}') # 1. What state is it in? -weight: 500;">kubectl get pod <name> -o wide # 2. Why? (look at Events section at the bottom) -weight: 500;">kubectl describe pod <name> # 3. What is it saying? -weight: 500;">kubectl logs <name> -weight: 500;">kubectl logs <name> --previous # if already crashed # 4. Can it reach its dependencies? -weight: 500;">kubectl exec -it <name> -- -weight: 500;">curl http://<-weight: 500;">service-name>:<port>/health # 5. What are its resource limits? -weight: 500;">kubectl describe pod <name> | grep -A3 Limits # 6. Check node pressure -weight: 500;">kubectl describe node $(-weight: 500;">kubectl get pod <name> -o jsonpath='{.spec.nodeName}') # 1. What state is it in? -weight: 500;">kubectl get pod <name> -o wide # 2. Why? (look at Events section at the bottom) -weight: 500;">kubectl describe pod <name> # 3. What is it saying? -weight: 500;">kubectl logs <name> -weight: 500;">kubectl logs <name> --previous # if already crashed # 4. Can it reach its dependencies? -weight: 500;">kubectl exec -it <name> -- -weight: 500;">curl http://<-weight: 500;">service-name>:<port>/health # 5. What are its resource limits? -weight: 500;">kubectl describe pod <name> | grep -A3 Limits # 6. Check node pressure -weight: 500;">kubectl describe node $(-weight: 500;">kubectl get pod <name> -o jsonpath='{.spec.nodeName}')