Key Takeaways
- ✓kubectl operates on Kubernetes objects (Pods, Deployments), not directly on containers
- ✓Always prefer kubectl apply (declarative) over imperative commands to ensure reproducibility
TL;DR: This kubectl commands cheatsheet lets you quickly transition from Docker CLI to Kubernetes. Each Docker command finds its kubectl equivalent with exact syntax, examples, and common pitfalls. Print this reference and keep it handy.
This topic is at the core of the LFD459 Kubernetes for Application Developers training.
Why master kubectl when you know Docker?
According to the CNCF Annual Survey 2025, 82% of container users run Kubernetes in production. Your Docker expertise remains valuable, but you now need to translate your reflexes to kubectl.
Key takeaway: kubectl and Docker CLI share similar concepts (containers, images, logs), but kubectl operates on Kubernetes objects (Pods, Deployments, Services) not directly on containers.
To deepen the fundamentals, check our Kubernetes Training: Complete Guide.
Essential kubectl commands vs Docker CLI: Quick reference table
| Action | Docker CLI | kubectl |
|---|---|---|
| List containers/pods | docker ps | kubectl get pods |
| List all (including stopped) | docker ps -a | kubectl get pods --all-namespaces |
| View details | docker inspect | kubectl describe pod |
| Real-time logs | docker logs -f | kubectl logs -f |
| Interactive shell | docker exec -it | kubectl exec -it |
| Delete | docker rm | kubectl delete pod |
| List images | docker images | kubectl get pod |
Memorize this key difference: Docker manages individual containers, kubectl orchestrates Pods (groups of containers).
For an in-depth orchestrator comparison, check Kubernetes vs Docker Swarm: Which orchestrator to choose in 2026?.
Pod management: kubectl commands you'll use daily
Creation and deployment
# Docker: run a container
docker run -d --name nginx -p 80:80 nginx:1.25
# kubectl: create a Pod (imperative method)
kubectl run nginx --image=nginx:1.25 --port=80
# kubectl: create via YAML file (recommended declarative method)
kubectl apply -f nginx-pod.yaml
Always prefer kubectl apply for reproducibility. You can explore Kubernetes Tutorials and Practical Guides for complete examples.
Inspection and debugging
# Quick status of all your pods
kubectl get pods -o wide
# Complete details of a pod
kubectl describe pod nginx-7fb9
# Pod in CrashLoopBackOff? Check the state:
kubectl describe pod <name> | grep -A5 "State:"
kubectl logs <name> --previous
# Recent cluster events
kubectl get events --sort-by='.lastTimestamp' | tail -20
Key takeaway: kubectl describe gives you Events at the bottom of the output. Check them systematically to diagnose scheduling failures or image pull issues.
Image and build management: docker vs kubectl quick reference
| Action | Docker | kubectl / Kubernetes |
|---|---|---|
| Build image | docker build -t app:v1 . | N/A (use docker/buildah/kaniko) |
| Push image | docker push registry/app:v1 | N/A (managed outside cluster) |
| Pull image | docker pull nginx | Automatic at deployment |
| View pod's image | N/A | kubectl get pod |
According to DevOpsCube, your microservices images should stay under 200MB. Multi-stage builds reduce images from 800MB to 15-30MB (Cloud Native Now).
Optimize your Dockerfiles before deploying to Kubernetes. Compare options in our Kubernetes Distributions Comparison Table 2026.
Networking and service exposure
| Action | Docker | kubectl |
|---|---|---|
| Expose a port | docker run -p 8080:80 | kubectl expose pod nginx --port=80 --type=NodePort |
| List ports | docker port | kubectl get svc |
| Internal network | docker network create | Services, NetworkPolicies |
| Internal DNS | --link (deprecated) | |
# Create a Service to expose your application
kubectl expose deployment nginx --port=80 --target-port=80 --type=ClusterIP
# Access temporarily from your machine
kubectl port-forward svc/nginx 8080:80
Use port-forward for local debugging, never in production. For managed services, check EKS vs GKE vs AKS: Complete Comparison.
Volumes and persistence: kubectl equivalents
| Docker | kubectl / Kubernetes |
|---|---|
docker volume create | kubectl apply -f pvc.yaml |
-v /host:/container | hostPath (not recommended in prod) |
--mount type=bind | PersistentVolumeClaim |
docker volume ls | kubectl get pv,pvc |
# Minimal PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-pvc
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
# Check your volumes status
kubectl get pvc
kubectl describe pvc data-pvc
Key takeaway: In Kubernetes, always separate storage (PV) from the claim (PVC). This enables portability between environments.
Deployment and scaling commands
# Docker Compose: scale
docker-compose up --scale web=3
# kubectl: create a Deployment with 3 replicas
kubectl create deployment nginx --image=nginx:1.25 --replicas=3
# Scale an existing Deployment
kubectl scale deployment nginx --replicas=5
# Rolling update
kubectl set image deployment/nginx nginx=nginx:1.26
# Rollback if problem
kubectl rollout undo deployment/nginx
Always check rollout status:
kubectl rollout status deployment/nginx
kubectl rollout history deployment/nginx
To prepare for CKAD certification, the passing score is 66% in 2 hours (Linux Foundation).
Common pitfalls: what you must avoid
| Common Mistake | Solution |
|---|---|
Forgetting -- before exec command | kubectl exec -it pod -- /bin/sh (not kubectl exec -it pod /bin/sh) |
| Confusing pod and deployment | Delete the Deployment, not the Pod (it will be recreated) |
| Ignoring namespace | Add -n or --all-namespaces |
| No context configured | kubectl config use-context |
# Error: command ignored
kubectl exec -it nginx sh # ❌
# Correct: double dash mandatory
kubectl exec -it nginx -- sh # ✅
# Properly delete an application
kubectl delete deployment nginx # ✅ (not kubectl delete pod nginx-xxx)
As TealHQ points out: "Don't let your knowledge remain theoretical - set up a real Kubernetes environment to solidify your skills."
Check the Kubernetes system administrator path to structure your learning.
kubectl contexts and configuration
# See your current configuration
kubectl config view
kubectl config current-context
# Change cluster/context
kubectl config use-context production-cluster
# Set a default namespace
kubectl config set-context --current --namespace=app-namespace
Key takeaway: Configure a default namespace for each project. You'll avoid deployment errors in the wrong environment.
For managed cloud environments, explore Amazon EKS in Production: Feedback.
Resources and quotas
# View CPU/memory consumption of pods
kubectl top pods
kubectl top nodes
# Describe namespace limits
kubectl describe resourcequota -n <namespace>
Compare different approaches in our Kubernetes Comparisons and Alternatives hub.
Take action: Certification trainings
This kubectl commands cheatsheet gives you the basics. To master Kubernetes in real situations and get your certification:
- Developers: LFD459 Kubernetes for Application Developers (3 days, prepares for CKAD)
- Administrators: LFS458 Kubernetes Administration (4 days, prepares for CKA)
- Beginners: Kubernetes Fundamentals (1 day, discovery). To go deeper, check our OpenShift vs Native Kubernetes.
According to the CNCF Training Report, 104,000 people have taken the CKA exam with 49% annual growth. Join them.