82.1 Project 85: GitOps with Argo CD
Friends, Git becomes the desired state. Today we install Argo CD, point it at a repo, and sync a Deployment until live matches git.
मित्रांनो, Git desired state होतो. आज Argo CD install, repo कडे point, आणि Deployment sync जोपर्यंत live git जुळत नाही.
दोस्तों, Git desired state बनता है. आज Argo CD install, repo की ओर point, और Deployment sync जब तक live git से न मिले.
What you will build in this project
- Install Argo CD in a cluster.
- Register an app from git.
- Sync and verify pods.
- Prove a git revert rolls back the cluster.
1. Start from a real company story
At PhonePe in Bengaluru, kubectl apply from laptops drifted three clusters and a Friday outage took two hours to untangle.
Rough cost: about ₹28 lakh in failed UPI retries.
Ananya put every manifest in git and let Argo CD sync.
Today we wire that GitOps loop.
Ravindra Bagale's Tip
Students click Sync forever and ignore OutOfSync. Fix the git source; do not paper over with manual kubectl. Keep that habit.
Students नेहमी Sync क्लिक करतात आणि OutOfSync दुर्लक्ष करतात. Git source दुरुस्त करा; kubectl ने झाकू नका. सवय ठेवा.
Students हमेशा Sync क्लिक करते हैं और OutOfSync अनदेखा करते हैं. Git source ठीक करें; kubectl से ढकें नहीं. आदत रखिए.
2. Start and prepare
Step 1: Why GitOps
Why: Laptops drift. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: echo why. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 1: a1
Type this:
echo 'Git commit is the change request and the audit log'
You will see:
Git commit is the change request and the audit log
What it means: Why.
Example 2: a2
Type this:
mkdir -p /tmp/argo85 && echo 'Today: install Argo CD, app, sync, revert'
You will see:
Today: install Argo CD, app, sync, revert
What it means: Scope.
Example 3: a3
Type this:
echo 'Desired state lives in git; the controller makes the cluster match'
You will see:
Desired state lives in git; the controller makes the cluster match
What it means: Model.
Step 2: Install Argo CD
Why: Namespace and manifest. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: install tip. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 4: b1
Type this:
printf '%s\n' 'kubectl create namespace argocd' 'kubectl apply -n argocd -f https://example.com/argo-cd/install.yaml' > /tmp/argo85/INSTALL.txt && cat /tmp/argo85/INSTALL.txt
You will see:
kubectl create namespace argocd
What it means: Install.
Example 5: b2
Type this:
echo 'Wait: kubectl -n argocd get pods until all Running'
You will see:
Wait: kubectl -n argocd get pods until all Running
What it means: Wait.
Example 6: b3
Type this:
echo 'Port-forward: kubectl -n argocd port-forward svc/argocd-server 8080:443'
You will see:
Port-forward: kubectl -n argocd port-forward svc/argocd-server 8080:443
What it means: UI.
Step 3: Initial password
Why: Admin secret. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: secret. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 7: c1
Type this:
echo 'kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath={.data.password} | base64 -d'
You will see:
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath={.data.password} | base64 -d
What it means: Password.
Example 8: c2
Type this:
echo 'User is admin; change the password after first login'
You will see:
User is admin; change the password after first login
What it means: User.
Example 9: c3
Type this:
echo 'argocd login localhost:8080 --username admin'
You will see:
argocd login localhost:8080 --username admin
What it means: CLI login.
3. Build the main pieces
Step 4: App from git
Why: Register. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: app create. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 10: d1
Type this:
printf '%s\n' 'argocd app create shop-api \' ' --repo https://git.example.com/shop/deploy.git \' ' --path apps/shop-api \' ' --dest-server https://kubernetes.default.svc \' ' --dest-namespace shop' > /tmp/argo85/APP.txt && cat /tmp/argo85/APP.txt
You will see:
--path apps/shop-api \
What it means: App.
Example 11: d2
Type this:
echo 'Use a private deploy repo; app repos stay separate from source code if you prefer'
You will see:
Use a private deploy repo; app repos stay separate from source code if you prefer
What it means: Repos.
Example 12: d3
Type this:
echo 'Auto-create namespace: --sync-option CreateNamespace=true'
You will see:
Auto-create namespace: --sync-option CreateNamespace=true
What it means: NS.
Step 5: Sync
Why: Make live match. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: sync. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 13: e1
Type this:
echo 'argocd app sync shop-api'
You will see:
argocd app sync shop-api
What it means: Sync.
Example 14: e2
Type this:
echo 'argocd app get shop-api'
You will see:
argocd app get shop-api
What it means: Get.
Example 15: e3
Type this:
printf '%s\n' 'Healthy + Synced means live matches git' > /tmp/argo85/STATUS.txt && cat /tmp/argo85/STATUS.txt
You will see:
Healthy + Synced means live matches git
What it means: Status.
Step 6: Autosync
Why: Optional. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: policy. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 16: f1
Type this:
echo 'argocd app set shop-api --sync-policy automated --auto-prune --self-heal'
You will see:
argocd app set shop-api --sync-policy automated --auto-prune --self-heal
What it means: Auto.
Example 17: f2
Type this:
echo 'Self-heal undoes kubectl drift by re-applying git'
You will see:
Self-heal undoes kubectl drift by re-applying git
What it means: Heal.
Example 18: f3
Type this:
printf '%s\n' 'Acceptance: edit Deployment in git, commit, Argo syncs without laptop kubectl' > /tmp/argo85/ACCEPT.txt && cat /tmp/argo85/ACCEPT.txt
You will see:
Acceptance: edit Deployment in git, commit, Argo syncs without laptop kubectl
What it means: Gate.
4. Automate and verify
Step 7: OutOfSync
Why: Read the diff. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: diff. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 19: g1
Type this:
echo 'argocd app diff shop-api'
You will see:
argocd app diff shop-api
What it means: Diff.
Example 20: g2
Type this:
echo 'Fix git or accept a deliberate sync; never ignore forever'
You will see:
Fix git or accept a deliberate sync; never ignore forever
What it means: Fix.
Example 21: g3
Type this:
echo 'Common cause: someone ran kubectl set image by hand'
You will see:
Common cause: someone ran kubectl set image by hand
What it means: Cause.
Step 8: Rollback
Why: Git revert. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: revert. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 22: h1
Type this:
echo 'git revert HEAD && git push'
You will see:
git revert HEAD && git push
What it means: Revert.
Example 23: h2
Type this:
echo 'Argo sees the old manifest and syncs back'
You will see:
Argo sees the old manifest and syncs back
What it means: Sync back.
Example 24: h3
Type this:
echo 'argocd app history shop-api shows sync waves'
You will see:
argocd app history shop-api shows sync waves
What it means: History.
Step 9: RBAC tip
Why: Who can sync. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: rbac. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 25: i1
Type this:
printf '%s\n' 'Devs open PRs to the deploy repo' 'Platform approves and merges' 'Argo syncs; no cluster admin for app teams' > /tmp/argo85/RBAC.txt && cat /tmp/argo85/RBAC.txt
You will see:
Platform approves and merges
What it means: RBAC.
Example 26: i2
Type this:
echo 'Project AppProject limits which repos and namespaces an app may use'
You will see:
Project AppProject limits which repos and namespaces an app may use
What it means: AppProject.
Example 27: i3
Type this:
echo 'SSO to Argo CD with your company IdP'
You will see:
SSO to Argo CD with your company IdP
What it means: SSO.
5. Harden and accept
Step 10: Story PhonePe
Why: Laptop drift. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: story. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 28: j1
Type this:
printf '%s\n' 'At PhonePe in Bengaluru, kubectl from laptops drifted three clusters.' 'Ananya put manifests in git and let Argo CD sync.' > /tmp/argo85/STORY.txt && wc -l /tmp/argo85/STORY.txt
You will see:
2 /tmp/argo85/STORY.txt
What it means: Story.
Example 29: j2
Type this:
echo 'Rough cost: about ₹28 lakh in failed UPI retries'
You will see:
Rough cost: about ₹28 lakh in failed UPI retries
What it means: Cost.
Example 30: j3
Type this:
echo 'Ananya: PASS'
You will see:
Ananya: PASS
What it means: Sign-off.
Step 11: Proof
Why: Files. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: ls. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 31: k1
Type this:
ls /tmp/argo85
You will see:
ACCEPT.txt\nAPP.txt\nINSTALL.txt\nRBAC.txt\nSTATUS.txt\nSTORY.txt
What it means: Tree.
Example 32: k2
Type this:
grep Synced /tmp/argo85/STATUS.txt
You will see:
Healthy + Synced means live matches git
What it means: Synced.
Example 33: k3
Type this:
echo 'Next: Multi-environment GitOps project 86'
You will see:
Next: Multi-environment GitOps project 86
What it means: Bridge.
Step 12: Acceptance
Why: Git drives the cluster. We do this before the next step so mistakes stay small and easy to undo. Read the output carefully; the numbers and names tell you if the machine is healthy.
What: final. Follow the numbered examples below. Type each command, read the exact output, and match the meaning line before you move on. That is how real teams learn a tool.
Example 34: z1
Type this:
echo 'Argo CD installed'
You will see:
Argo CD installed
What it means: Install.
Example 35: z2
Type this:
echo 'App Synced and Healthy'
You will see:
App Synced and Healthy
What it means: Sync.
Example 36: z3
Type this:
echo 'Git revert rolls back pods'
You will see:
Git revert rolls back pods
What it means: Revert.
Check yourself
Q1. Who fixed PhonePe drift?
Ananya
Q2. Tool?
Argo CD
Q3. Source of truth?
git
Q4. Bad state word?
OutOfSync
Q5. Rollback how?
git revert
Q6. Manual kubectl in prod?
no
Friends, you synced a cluster from git with Argo CD. Did you understand? Let us try it once more. Break the image tag in git, sync, then revert and prove pods heal.
मित्रांनो, तुम्ही Argo CD ने cluster git वरून sync केला. Git मध्ये image tag मोडा, sync करा, मग revert करून pods बरे होतात हे सिद्ध करा.
दोस्तों, आपने Argo CD से cluster git से sync किया. Git में image tag तोड़ें, sync करें, फिर revert कर pods ठीक हों, यह साबित करें.
Lab: try at home
- Install Argo CD.
- Register app.
- Sync.
- Git revert heals cluster.
Recap
- Git is desired state.
- Argo watches the repo.
- Sync makes live match.
- Revert is rollback.
- No laptop kubectl in prod.