Key Takeaways
- ✓50+ essential kubectl commands organized by use case category
- ✓IT teams spend an average of 34 work days per year resolving Kubernetes issues - mastering kubectl drastically reduces this time
TL;DR: This kubectl Kubernetes commands cheatsheet gathers the 50+ essential commands for any Kubernetes system administrator, Backend developer, or software engineer working with Kubernetes. With 82% of container users running Kubernetes in production (CNCF 2025), mastering kubectl has become essential.
This skill is at the core of the LFS458 Kubernetes Administration training.
Quick reference: The 15 most used commands
| Command | Action | Example |
|---|---|---|
kubectl get pods | List pods | kubectl get pods -A -o wide |
kubectl describe | Resource details | kubectl describe pod nginx-abc123 |
kubectl logs | Show logs | kubectl logs -f pod/nginx --tail=100 |
kubectl apply -f | Apply a manifest | kubectl apply -f deployment.yaml |
kubectl delete | Delete a resource | kubectl delete pod nginx-abc123 |
kubectl exec | Execute in a pod | kubectl exec -it nginx -- /bin/sh |
kubectl create | Create a resource | kubectl create ns production |
kubectl scale | Modify replicas | kubectl scale deploy nginx --replicas=5 |
kubectl rollout | Manage deployments | kubectl rollout status deploy/nginx |
kubectl port-forward | Tunnel to a pod | kubectl port-forward svc/nginx 8080:80 |
kubectl cp | Copy files | kubectl cp pod:/path ./local |
kubectl top | CPU/RAM metrics | kubectl top pods --sort-by=memory |
kubectl config | Manage contexts | kubectl config use-context prod |
kubectl edit | Modify live | kubectl edit deploy nginx |
kubectl patch | Partial modification | kubectl patch deploy nginx -p '...' |
Key takeaway: IT teams spend an average of 34 work days per year resolving Kubernetes issues (Cloud Native Now). Mastering this cheatsheet drastically reduces this time.
How to navigate between clusters and namespaces?
# List available contexts
kubectl config get-contexts
# Change context
kubectl config use-context production-cluster
# Set default namespace
kubectl config set-context --current --namespace=production
# See current context
kubectl config current-context
Resource shortcuts
| Shortcut | Full Resource |
|---|---|
po | pods |
deploy | deployments |
svc | services |
ns | namespaces |
cm | configmaps |
pv | persistentvolumes |
pvc | persistentvolumeclaims |
ing | ingress |
no | nodes |
rs | replicasets |
Check the Kubernetes Memo: objects, API resources and shortcuts for the complete list.
Which commands for managing Pods?
# List all pods with details
kubectl get pods -A -o wide
# Pods from a specific namespace
kubectl get pods -n production
# Filter by label
kubectl get pods -l app=nginx,env=prod
# Sort by creation date
kubectl get pods --sort-by=.metadata.creationTimestamp
# JSON/YAML format
kubectl get pod nginx-abc123 -o yaml
kubectl get pods -o json | jq '.items[].metadata.name'
# Delete a pod (force)
kubectl delete pod nginx-abc123 --grace-period=0 --force
Execution in a pod
# Interactive shell
kubectl exec -it nginx-abc123 -- /bin/bash
# Single command
kubectl exec nginx-abc123 -- cat /etc/nginx/nginx.conf
# In a specific container (multi-container pod)
kubectl exec -it nginx-abc123 -c sidecar -- /bin/sh
How to manage Deployments and ReplicaSets?
# Create a deployment
kubectl create deployment nginx --image=nginx:1.25 --replicas=3
# Apply from a file
kubectl apply -f deployment.yaml
# Update the image
kubectl set image deploy/nginx nginx=nginx:1.26
# Revision history
kubectl rollout history deploy/nginx
# Rollback
kubectl rollout undo deploy/nginx
kubectl rollout undo deploy/nginx --to-revision=2
# Pause/Resume
kubectl rollout pause deploy/nginx
kubectl rollout resume deploy/nginx
# Scale
kubectl scale deploy/nginx --replicas=10
kubectl autoscale deploy/nginx --min=3 --max=10 --cpu-percent=80
Key takeaway: 71% of Fortune 100 companies use Kubernetes in production (CNCF Project Journey Report). Automatic scaling via kubectl autoscale is the norm.
To dive deeper into deployment strategies, check the Kubernetes Tutorials and Practical Guides.
Which commands for Services and networking?
# Expose a deployment
kubectl expose deploy nginx --port=80 --type=ClusterIP
kubectl expose deploy nginx --port=80 --type=LoadBalancer
# List services
kubectl get svc -A
# Service details
kubectl describe svc nginx
# Port-forward for local debug
kubectl port-forward svc/nginx 8080:80
kubectl port-forward pod/nginx-abc123 8080:80
# Check endpoints
kubectl get endpoints nginx
NetworkPolicies
# List policies
kubectl get networkpolicies -A
# Apply a policy
kubectl apply -f network-policy.yaml
Refer to the NetworkPolicies Quick Reference for YAML examples.
How to manipulate ConfigMaps and Secrets?
# Create a ConfigMap
kubectl create configmap app-config --from-literal=ENV=production
kubectl create configmap app-config --from-file=config.properties
# Create a Secret
kubectl create secret generic db-creds \
--from-literal=username=admin \
--from-literal=password=secret123
# Decode a secret
kubectl get secret db-creds -o jsonpath='{.data.password}' | base64 -d
# List
kubectl get configmaps,secrets -n production
Key takeaway: Never commit Secrets in plain text. Use tools like Sealed Secrets or External Secrets Operator.
These practices are taught in the LFD459 Kubernetes for Developers training.
Which commands for Kubernetes debugging?
Debugging is the key skill for Kubernetes Backend developers and software engineers.
# Pod logs
kubectl logs nginx-abc123
kubectl logs nginx-abc123 --previous # Previous container (crash)
kubectl logs nginx-abc123 -f --tail=100 # Follow in real time
kubectl logs -l app=nginx --all-containers # All pods from a label
# Cluster events
kubectl get events --sort-by='.lastTimestamp' | tail -30
kubectl get events -n production --field-selector type=Warning
# Describe a resource (complete diagnostic)
kubectl describe pod nginx-abc123 | grep -A10 "Events:"
# Metrics (requires metrics-server)
kubectl top nodes
kubectl top pods --sort-by=memory
kubectl top pods --containers
# Debug with an ephemeral pod (K8s 1.25+)
kubectl debug -it nginx-abc123 --image=busybox --target=nginx
Network diagnostics
# Check DNS resolution
kubectl run debug --rm -it --image=busybox -- nslookup kubernetes
# Test connectivity
kubectl run debug --rm -it --image=curlimages/curl -- curl -v http://nginx:80
# Check endpoints
kubectl get endpoints nginx
For advanced techniques, check Solving the 10 Most Common Kubernetes Deployment Errors.
What are common errors and their solutions?
| Error | Diagnostic | Solution |
|---|---|---|
CrashLoopBackOff | kubectl logs | Check image, env variables, probes |
ImagePullBackOff | kubectl describe pod | Fix image name or registry credentials |
Pending | kubectl describe pod | Check resources, PVC, node selectors |
OOMKilled | kubectl describe pod | Increase resources.limits.memory |
CreateContainerConfigError | kubectl describe pod | Missing or incorrect ConfigMap/Secret |
# Quick CrashLoopBackOff diagnostic
kubectl describe pod nginx-abc123 | grep -A5 "State:"
kubectl logs nginx-abc123 --previous
# Check available resources
kubectl describe nodes | grep -A5 "Allocated resources"
# Pod stuck in Terminating
kubectl delete pod nginx-abc123 --force --grace-period=0
As TealHQ points out: "Don't let your knowledge remain theoretical, set up a real Kubernetes environment to solidify your skills."
Test these commands with Minikube vs Kind vs K3s.
Advanced commands for administration
# Drain a node (maintenance)
kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data
# Cordon/Uncordon
kubectl cordon node-1
kubectl uncordon node-1
# Taints and tolerations
kubectl taint nodes node-1 key=value:NoSchedule
# Labels
kubectl label nodes node-1 disktype=ssd
kubectl label pods nginx-abc123 env=prod --overwrite
# Annotations
kubectl annotate pod nginx-abc123 description="Production nginx"
# Dry-run for validation
kubectl apply -f deployment.yaml --dry-run=client
kubectl apply -f deployment.yaml --dry-run=server
For advanced cluster administration, explore Kubernetes Comparisons and Alternatives.
Take action: Certification trainings
This kubectl Kubernetes commands cheatsheet covers the basics. To develop recognized expertise:
SFEIR Institute Trainings:
- LFS458 Kubernetes Administration: 4 days to prepare for CKA
- LFD459 Kubernetes for Developers: 3 days to prepare for CKAD
- LFS460 Kubernetes Security: 4 days to prepare for CKS
- Kubernetes Fundamentals: 1 day to discover Kubernetes
Key takeaway: The CKA certification tests practical skills. According to TechiesCamp: "The CKA exam tested practical, useful skills. It wasn't just theory, it matched real-world situations you'd actually run into."
Discover the Complete Kubernetes Training Guide to build your path.