Key Takeaways
- ✓kubectl apply, rollout, scale: essential commands for deploying to production
- ✓kubectl rollout undo enables instant rollback when deployment issues occur
TL;DR: This kubectl production cheatsheet gives you essential commands for deploying, updating, and debugging your Kubernetes applications. Each command includes exact syntax and practical examples to make you operational immediately.
To master these commands in real conditions, discover the LFD459 Kubernetes for Application Developers training.
What are the essential kubectl deployment commands?
The fundamental kubectl deployment commands cover creating, updating, and deleting resources. According to the CNCF Annual Survey 2025, 82% of container users run Kubernetes in production. Master these commands to join this majority.
| Command | Function | Example |
|---|---|---|
kubectl apply -f | Apply a config | kubectl apply -f deployment.yaml |
kubectl create deployment | Create a deployment | kubectl create deployment nginx --image=nginx:1.27 |
kubectl delete | Delete a resource | kubectl delete deployment nginx |
kubectl scale | Modify replica count | kubectl scale deployment nginx --replicas=5 |
kubectl set image | Update the image | kubectl set image deployment/nginx nginx=nginx:1.28 |
# You deploy a complete application
kubectl apply -f deployment.yaml -f service.yaml -f ingress.yaml
# You verify the status immediately
kubectl get deployment nginx -o wide
Key takeaway: Always usekubectl applyrather thankubectl createfor your deployments. Apply is declarative and idempotent.
Check our complete Kubernetes CI/CD guide to automate these commands.
How to use kubectl rollout reference to manage your updates?
The kubectl rollout command lets you control progressive updates of your deployments. This kubectl rollout reference covers all production use cases.
| Command | Description | Usage |
|---|---|---|
kubectl rollout status | Track progress | kubectl rollout status deployment/nginx |
kubectl rollout history | Revision history | kubectl rollout history deployment/nginx |
kubectl rollout undo | Rollback | kubectl rollout undo deployment/nginx |
kubectl rollout restart | Restart all pods | kubectl rollout restart deployment/nginx |
kubectl rollout pause | Suspend the rollout | kubectl rollout pause deployment/nginx |
kubectl rollout resume | Resume the rollout | kubectl rollout resume deployment/nginx |
# You launch an update and track its status
kubectl set image deployment/api api=api:v2.1.0
kubectl rollout status deployment/api --timeout=5m
# You notice a problem? Immediate rollback
kubectl rollout undo deployment/api
# You want to return to a specific revision
kubectl rollout history deployment/api
kubectl rollout undo deployment/api --to-revision=3
Key takeaway: Configure revisionHistoryLimit: 10 in your spec to keep enough rollback history.
To dive deeper into Kubernetes deployment strategies, check our complete comparison table.
Which kubectl commands for debugging in production?
Kubernetes debugging requires specific commands to inspect pods, logs, and events. Here's your kubectl production cheatsheet for diagnostics.
| Command | Usage | Example |
|---|---|---|
kubectl describe | Complete details | kubectl describe pod nginx-7fb9 |
kubectl logs | Container logs | kubectl logs nginx-7fb9 -f --tail=100 |
kubectl exec | Shell access | kubectl exec -it nginx-7fb9 -- /bin/sh |
kubectl get events | Cluster events | kubectl get events --sort-by='.lastTimestamp' |
kubectl top | CPU/RAM metrics | kubectl top pods --containers |
# You diagnose a pod in CrashLoopBackOff
kubectl describe pod <name> | grep -A10 "State:"
kubectl logs <name> --previous
# You search for recent events
kubectl get events -n production --sort-by='.lastTimestamp' | tail -20
# You inspect consumed resources
kubectl top pods -n production --sort-by=memory
Key takeaway: The --previous option shows you the logs from the previous container after a crash.
To go further, check our Kubernetes Monitoring and Troubleshooting section.
How does the Backend developer use the LFD459 Kubernetes for Application Developers training?
The LFD459 training prepares you to master kubectl for cloud-native application deployment. According to Linux Foundation Training, this 3-day training covers exactly these kubectl deployment commands.
| LFD459 Skill | Associated Commands |
|---|---|
| App Deployment | kubectl apply, kubectl create, kubectl scale |
| Configuration | kubectl create configmap, kubectl create secret |
| Service Exposure | kubectl expose, kubectl port-forward |
| Debugging | kubectl logs, kubectl exec, kubectl describe |
# You create a ConfigMap from a file
kubectl create configmap app-config --from-file=config.yaml
# You create a Secret for your credentials
kubectl create secret generic db-creds \
--from-literal=username=admin \
--from-literal=password=s3cr3t
# You expose your application
kubectl expose deployment api --port=80 --target-port=8080 --type=ClusterIP
Which kubectl commands for managing network resources?
Network commands let you configure Services, Ingress, and Network Policies. Here are the essentials for your production.
| Command | Function | Example |
|---|---|---|
kubectl expose | Create a Service | kubectl expose deploy nginx --port=80 |
kubectl port-forward | Local tunnel | kubectl port-forward svc/nginx 8080:80 |
kubectl get endpoints | Verify routing | kubectl get endpoints nginx |
# You test a service locally
kubectl port-forward svc/api 8080:80 &
curl localhost:8080/health
# You verify the service routes to the right pods
kubectl get endpoints api -o yaml
# You inspect network policies
kubectl get networkpolicies -A
Check our GitOps and Kubernetes guide to automate these configurations.
Common errors and quick solutions
These kubectl errors frequently block developers. Here's how to resolve them.
| Error | Probable Cause | Solution |
|---|---|---|
ImagePullBackOff | Image not found or auth | Verify registry and imagePullSecrets |
CrashLoopBackOff | Application crashing | kubectl logs |
Pending | Insufficient resources | kubectl describe pod → Events |
OOMKilled | Memory exceeded | Increase resources.limits.memory |
CreateContainerConfigError | Missing ConfigMap/Secret | Verify references in manifest |
# You diagnose an ImagePullBackOff
kubectl describe pod <name> | grep -A5 "Events:"
# You verify your registry authentication secrets
kubectl get secrets -o name | grep docker
# You manually test the pull
kubectl run test --image=<your-image> --restart=Never
Key takeaway: Always start with kubectl describe to understand the origin of an error.
For in-depth diagnostics, use our error resolution guide.
Advanced commands for Backend developers LFD459 Kubernetes for Application Developers training
These advanced commands distinguish you in production. Master them to become a Kubernetes expert.
# You apply a manifest with dry-run for validation
kubectl apply -f deployment.yaml --dry-run=client -o yaml
# You export current config of a deployment
kubectl get deployment nginx -o yaml > backup.yaml
# You quickly patch a resource
kubectl patch deployment nginx -p '{"spec":{"replicas":3}}'
# You monitor changes in real time
kubectl get pods -w
# You filter by labels
kubectl get pods -l app=nginx,env=production
| Recommended Alias | Full Command |
|---|---|
k | kubectl |
kgp | kubectl get pods |
kaf | kubectl apply -f |
kdp | kubectl describe pod |
kl | kubectl logs -f |
Add these aliases to your ~/.bashrc:
alias k='kubectl'
alias kgp='kubectl get pods'
alias kaf='kubectl apply -f'
Check the production deployment checklist before your next deployment.
Take action
This kubectl production cheatsheet gives you the foundations. To master these commands in real scenarios and validate your skills:
- LFD459 Kubernetes for Developers: 3 days to prepare for CKAD
- Kubernetes Fundamentals: discover the basics in 1 day
- LFS458 Kubernetes Administration: 4 days for CKA. To go deeper, check our Kubernetes system administrator content.
Also check our complete Kubernetes Training guide and our Kubernetes Deployment and Production hub to deepen your knowledge.