Cheatsheet6 min read

kubectl Cheatsheet: Essential Deployment Commands

SFEIR Institute

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.

CommandFunctionExample
kubectl apply -fApply a configkubectl apply -f deployment.yaml
kubectl create deploymentCreate a deploymentkubectl create deployment nginx --image=nginx:1.27
kubectl deleteDelete a resourcekubectl delete deployment nginx
kubectl scaleModify replica countkubectl scale deployment nginx --replicas=5
kubectl set imageUpdate the imagekubectl 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 use kubectl apply rather than kubectl create for 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.

CommandDescriptionUsage
kubectl rollout statusTrack progresskubectl rollout status deployment/nginx
kubectl rollout historyRevision historykubectl rollout history deployment/nginx
kubectl rollout undoRollbackkubectl rollout undo deployment/nginx
kubectl rollout restartRestart all podskubectl rollout restart deployment/nginx
kubectl rollout pauseSuspend the rolloutkubectl rollout pause deployment/nginx
kubectl rollout resumeResume the rolloutkubectl 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.

CommandUsageExample
kubectl describeComplete detailskubectl describe pod nginx-7fb9
kubectl logsContainer logskubectl logs nginx-7fb9 -f --tail=100
kubectl execShell accesskubectl exec -it nginx-7fb9 -- /bin/sh
kubectl get eventsCluster eventskubectl get events --sort-by='.lastTimestamp'
kubectl topCPU/RAM metricskubectl 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 SkillAssociated Commands
App Deploymentkubectl apply, kubectl create, kubectl scale
Configurationkubectl create configmap, kubectl create secret
Service Exposurekubectl expose, kubectl port-forward
Debuggingkubectl 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.

CommandFunctionExample
kubectl exposeCreate a Servicekubectl expose deploy nginx --port=80
kubectl port-forwardLocal tunnelkubectl port-forward svc/nginx 8080:80
kubectl get endpointsVerify routingkubectl 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.

ErrorProbable CauseSolution
ImagePullBackOffImage not found or authVerify registry and imagePullSecrets
CrashLoopBackOffApplication crashingkubectl logs --previous
PendingInsufficient resourceskubectl describe pod → Events
OOMKilledMemory exceededIncrease resources.limits.memory
CreateContainerConfigErrorMissing ConfigMap/SecretVerify 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 AliasFull Command
kkubectl
kgpkubectl get pods
kafkubectl apply -f
kdpkubectl describe pod
klkubectl 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:

Also check our complete Kubernetes Training guide and our Kubernetes Deployment and Production hub to deepen your knowledge.