Cheatsheet5 min read

Cheatsheet: kubectl vs Docker CLI Commands Side by Side

SFEIR Institute

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

ActionDocker CLIkubectl
List containers/podsdocker pskubectl get pods
List all (including stopped)docker ps -akubectl get pods --all-namespaces
View detailsdocker inspect kubectl describe pod
Real-time logsdocker logs -f kubectl logs -f
Interactive shelldocker exec -it shkubectl exec -it -- sh
Deletedocker rm kubectl delete pod
List imagesdocker imageskubectl get pod -o jsonpath='{.spec.containers[*].image}'

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

ActionDockerkubectl / Kubernetes
Build imagedocker build -t app:v1 .N/A (use docker/buildah/kaniko)
Push imagedocker push registry/app:v1N/A (managed outside cluster)
Pull imagedocker pull nginxAutomatic at deployment
View pod's imageN/Akubectl get pod -o jsonpath='{.spec.containers[*].image}'

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

ActionDockerkubectl
Expose a portdocker run -p 8080:80kubectl expose pod nginx --port=80 --type=NodePort
List portsdocker port kubectl get svc
Internal networkdocker network createServices, NetworkPolicies
Internal DNS--link (deprecated)..svc.cluster.local
# 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

Dockerkubectl / Kubernetes
docker volume createkubectl apply -f pvc.yaml
-v /host:/containerhostPath (not recommended in prod)
--mount type=bindPersistentVolumeClaim
docker volume lskubectl 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 MistakeSolution
Forgetting -- before exec commandkubectl exec -it pod -- /bin/sh (not kubectl exec -it pod /bin/sh)
Confusing pod and deploymentDelete the Deployment, not the Pod (it will be recreated)
Ignoring namespaceAdd -n or --all-namespaces
No context configuredkubectl 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:

According to the CNCF Training Report, 104,000 people have taken the CKA exam with 49% annual growth. Join them.