This scenario teaches you how to see what will change in the cluster BEFORE applying YAML, similar to Git diff but for Kubernetes.
This is extremely useful in real DevOps workflows, especially CI/CD pipelines.
β Step 1 β Install kubectl diff plugin (only if missing)
Most cloud environments (GKE, EKS, AKS, Cloud Shell) already have it.
Check:
kubectl diff --help
If it shows help output, you're good.
ποΈ Step 2 β Create Initial Deployment
Create file:
# diff-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: diff-nginx
spec:
replicas: 2
selector:
matchLabels:
app: diff-nginx
template:
metadata:
labels:
app: diff-nginx
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80
Apply it:
kubectl apply -f diff-deploy.yaml
Verify:
kubectl get deploy diff-nginx
kubectl get pods -l app=diff-nginx
βοΈ Step 3 β Modify the YAML (but DO NOT apply yet)
Edit the same file diff-deploy.yaml and change:
- replicas: 2 β 3
- image: nginx:1.21 β nginx:1.25
Updated file:
spec:
replicas: 3
template:
spec:
containers:
- name: nginx
image: nginx:1.25
Save it.
π Step 4 β Preview Changes Using kubectl diff
Run:
kubectl diff -f diff-deploy.yaml
You will see something like:
--- /tmp/LIVE-#####
+++ /tmp/MERGED-#####
@@ -1,6 +1,6 @@
replicas: 2
+ replicas: 3
...
- image: nginx:1.21
+ image: nginx:1.25
This means:
- Kubernetes will update replicas from 2 β 3
- It will update image from 1.21 β 1.25
β No changes are applied yet β only preview.
π Step 5 β Apply the Changes
Once satisfied:
kubectl apply -f diff-deploy.yaml
Check rollout:
kubectl rollout status deployment/diff-nginx
Check pods:
kubectl get pods -l app=diff-nginx -o wide
π§ͺ Step 6 β Modify Again and Test More Changes
Letβs try one more change for deeper practice.
Edit again:
replicas: 3 β 1
Preview:
kubectl diff -f diff-deploy.yaml
You will see:
replicas: 3
β replicas: 1
Apply:
kubectl apply -f diff-deploy.yaml
π Thanks for reading! If this post added value, a like β€οΈ, follow, or share would encourage me to keep creating more content.
β Latchu | Senior DevOps & Cloud Engineer
βοΈ AWS | GCP | βΈοΈ Kubernetes | π Security | β‘ Automation
π Sharing hands-on guides, best practices & real-world cloud solutions




Top comments (0)