Kubectl Commands for Pod, ReplicaSet and Deployment
🚀 Kubernetes Pod, ReplicaSet & Deployment – Commands Cheat Sheet (with comments)
🟢 POD Commands
kubectl run nginx --image=nginx
# Create a simple pod quickly (imperative way)
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
# Generate pod YAML without creating it
kubectl apply -f pod.yaml
# Create pod from YAML
kubectl get pods
# List all pods
kubectl get pods -o wide
# Show pods with node + IP info
kubectl describe pod nginx
# Detailed info + events (best for troubleshooting)
kubectl logs nginx
# Show container logs
kubectl logs -f nginx
# Stream logs live (follow mode)
kubectl exec -it nginx -- bash
# Enter inside container shell
kubectl delete pod nginx
# Delete pod
🟡 REPLICASET Commands
kubectl apply -f rs.yaml
# Create ReplicaSet from YAML
kubectl get rs
# List ReplicaSets
kubectl describe rs myrs
# Detailed ReplicaSet info
kubectl scale rs myrs --replicas=5
# Increase/decrease number of pods
kubectl get pods -l app=myapp
# Show pods created by this ReplicaSet (label filter)
kubectl delete rs myrs
# Delete ReplicaSet and its pods
🔵 DEPLOYMENT Commands (Most used in real projects 🔥)
kubectl create deployment nginx --image=nginx
# Create deployment quickly
kubectl create deployment nginx --image=nginx --replicas=3
# Create deployment with 3 replicas
kubectl create deployment nginx --image=nginx --dry-run=client -o yaml > deploy.yaml
# Generate deployment YAML template
kubectl apply -f deploy.yaml
# Create/update deployment from YAML
kubectl get deploy
# List deployments
kubectl describe deploy nginx
# Detailed deployment info
kubectl scale deploy nginx --replicas=5
# Scale pods count
kubectl set image deploy/nginx nginx=nginx:1.25
# Update container image (rolling update)
kubectl rollout status deploy/nginx
# Watch rollout progress
kubectl rollout history deploy/nginx
# Show rollout versions
kubectl rollout undo deploy/nginx
# Rollback to previous version
kubectl rollout restart deploy/nginx
# Restart all pods safely
kubectl delete deploy nginx
# Delete deployment + ReplicaSet + pods
🔥 Common Commands (Works for all resources)
kubectl get all
# Show everything (pods, rs, deploy, svc)
kubectl get pods -w
# Watch changes live
kubectl edit deploy nginx
# Edit resource directly in editor
kubectl explain deployment.spec.template.spec.containers
# See YAML field explanation (very useful for exams)
kubectl delete -f deploy.yaml
# Delete resources created from file
kubectl get pods -l app=nginx
# Filter using labels
🎯 Memory trick (super helpful)
Think like this:
Pod → run
ReplicaSet → scale
Deployment → update + rollback
Comments
Post a Comment