Warrior, this is one of the most important chapters in the entire Kubernetes course.
You've already learned:
Git โ CI โ Docker โ Registry โ KubernetesNow we're going to change how Kubernetes deployments are controlled.
Instead of CI directly telling Kubernetes:
kubectl apply ...we'll use:
Git
โ
Argo CD
โ
KubernetesThis is called GitOps.
The simplest definition:
GitOps means using Git as the source of truth for the desired state of your infrastructure and applications, with an automated system continuously reconciling Kubernetes to that state.
Remember Chapter 1?
Kubernetes works using:
Desired State
โ
Controller
โ
Actual StateGitOps takes that idea and makes Git the source of the desired state.
Previously we learned:
Developer
โ
Git
โ
GitHub Actions
โ
Docker build
โ
Container Registry
โ
kubectl apply
โ
KubernetesFor example:
kubectl apply -f deployment.yamlThe CI server directly changes the cluster.
With GitOps:
Developer
โ
Git
โ
CI
โ
Docker Image
โ
Registry
Git
โ
Kubernetes manifests
โ
Argo CD
โ
KubernetesNotice something important:
CI doesn't necessarily need to directly deploy to Kubernetes.
Argo CD does.
Imagine someone manually changes production:
kubectl scale deployment node-api --replicas=10But Git says:
replicas: 3Now:
Git = 3
Kubernetes = 10The cluster has drifted from the desired configuration.
A GitOps controller can detect this difference.
Desired
3 replicas
Actual
10 replicas
โ
Drift detectedDepending on your Argo CD configuration, it can synchronize the cluster back to the Git-defined state.
This is extremely important:
Git
โ
Desired State
โ
โ
Argo CD
โ
Reconciliation
โ
โ
Kubernetes
โ
Actual State
โ
โ
Pods/ServicesArgo CD continuously compares:
Desired state
VS
Actual stateArgo CD is a GitOps continuous delivery tool for Kubernetes.
Its primary job is:
Git repository
โ
Read Kubernetes configuration
โ
Compare with cluster
โ
Synchronize
โ
KubernetesIt supports configurations such as:
This distinction is critical.
Usually handles:
Build
Test
Lint
Security
Docker imageHandles:
Deployment
Synchronization
Drift detection
ReconciliationSo:
CI
โ
Build artifact
Argo CD
โ
Deploy artifact/configurationA modern pipeline can look like:
Developer
โ
โ
Git
โ
โโโโโโโโโโโโดโโโโโโโโโโโ
โ โ
Application repo Deployment repo
โ โ
โ โ
CI Argo CD
โ โ
โ โ
Docker Image Kubernetes
โ โ
โ โ
Registry PodsThere are different repository structures, but the separation is useful to understand.
A common pattern:
node-api/
โโโ src/
โโโ package.json
โโโ Dockerfile
โโโ tests/k8s-config/
โโโ base/
โโโ overlays/
โโโ dev/
โโโ staging/
โโโ production/Then:
Application repo
โ
CI
โ
Docker image
โ
Registry
Deployment repo
โ
Argo CD
โ
KubernetesBecause application code and infrastructure configuration have different purposes.
Application repo:
"How does my application work?"Deployment repo:
"How should this application run?"For example:
replicas: 5is deployment configuration.
While:
app.get("/users")is application code.
GitOps can also use a single repository.
For example:
my-project/
โ
โโโ src/
โโโ Dockerfile
โ
โโโ k8s/
โโโ base/
โโโ overlays/Argo CD watches:
/k8sThis is perfectly valid.
The right structure depends on team size, release model, ownership, and organizational needs.
Suppose Git contains:
replicas: 3Argo CD sees:
Git = 3
Cluster = 3Everything is synchronized.
Now someone changes the cluster manually:
kubectl scale deployment node-api --replicas=7Now:
Git = 3
Cluster = 7Argo CD sees:
DRIFTIf automated sync/self-healing is configured, Argo CD can reconcile the cluster back toward Git's desired state.
This is the heart of GitOps.
Git
โ
โ
Desired State
replicas=3
โ
โ
Argo CD
โ
โ
Kubernetes Cluster
โ
โ
Actual State
replicas=3When they differ:
Desired = 3
Actual = 7
โ
DRIFTArgo CD can synchronize.
Argo CD introduces an important object:
ApplicationAn Argo CD Application tells Argo:
"This Git repository/path represents the desired state for this Kubernetes application."
Conceptually:
Argo CD Application
Repository:
github.com/company/platform
Path:
k8s/overlays/production
Destination:
production-clusterA simplified Application:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: node-api
spec:
project: default
source:
repoURL: https://github.com/example/k8s-config.git
targetRevision: main
path: overlays/production
destination:
server: https://kubernetes.default.svc
namespace: production
syncPolicy:
automated:
prune: true
selfHeal: trueLet's understand this piece by piece.
source#source:
repoURL: https://github.com/example/k8s-config.git
targetRevision: main
path: overlays/productionThis says:
Git repository
โ
main branch
โ
overlays/productionThat's where Argo CD gets the desired Kubernetes configuration.
destination#destination:
server: https://kubernetes.default.svc
namespace: productionThis specifies where the application should be deployed.
In a multi-cluster environment, the destination can identify a particular Kubernetes cluster.
syncPolicy#This controls synchronization behavior.
For example:
syncPolicy:
automated:
prune: true
selfHeal: trueThis enables automated reconciliation behavior.
selfHeal?#Imagine Git says:
replicas: 3Someone manually changes:
replicas = 10Argo CD detects:
Git = 3
Cluster = 10With self-healing enabled, Argo CD can restore the Git-defined state.
Conceptually:
Manual change
โ
Drift
โ
Argo CD detects
โ
Reconcile
โ
Back toward desired stateprune?#Suppose Git originally contains:
deployment.yaml
service.yaml
configmap.yamlThen someone removes:
configmap.yamlfrom Git.
Without appropriate pruning behavior, the old ConfigMap may remain in the cluster.
With pruning enabled:
Git
โ
ConfigMap removed
โ
Argo CD detects resource no longer desired
โ
Prune
โ
ConfigMap removed from clusterBe careful with pruning in production.
You want Git to be authoritative, but accidental Git changes can have real consequences.
Argo CD uses the concept of sync.
If:
Git desired state
โ
Cluster actual statethe application is out of sync.
Sync means:
Bring cluster toward Git-defined desired state.Argo CD provides a web UI where you can see:
Applications
Clusters
Resources
Sync status
Health
History
EventsYou might see:
node-api
SYNC: Synced
HEALTH: HealthyOr:
SYNC: OutOfSync
HEALTH: DegradedThis is extremely useful operationally.
These are different.
Answers:
Does the cluster match the Git configuration?
Possible conceptual state:
Synced
OutOfSyncAnswers:
Is the application/resource functioning according to Argo CD's health assessment?
Conceptually:
Healthy
Progressing
Degraded
Missing
UnknownYou can have:
Synced + DegradedFor example:
Git configuration = correctly applied
but
Pods = crashingSynceddoes not necessarily mean:
Application is healthy.It means the cluster matches the desired configuration.
Example:
Deployment says:
image: broken-image:v5Argo CD successfully applies it.
So:
SYNC = Synced
HEALTH = Degradedbecause the Pods may fail to start.
Let's say you release:
node-api v2Developer changes:
image:
tag: "v2"Then:
git commit
โ
git push
โ
Argo CD detects change
โ
OutOfSync
โ
Sync
โ
Kubernetes Deployment
โ
Rolling Update
โ
New Pods
โ
Readiness
โ
HealthyCI still builds the image.
For example:
Developer
โ
Git
โ
GitHub Actions
โ
Tests
โ
Docker Build
โ
RegistryThen CI needs to update the deployment configuration.
For example:
image:
tag: "a8f72c1"A commit is pushed to the deployment repository.
Then:
Deployment Git
โ
Argo CD
โ
KubernetesThis creates a clean separation.
Imagine CI builds:
node-api:a8f72c1Then it updates:
images:
- name: node-api
newTag: a8f72c1and commits that change.
Now:
Git
โ
new image reference
โ
Argo CD
โ
KubernetesThe deployment itself becomes Git-driven.
This is particularly relevant because Chapter 26 covered Kustomize.
Repository:
k8s/
โ
โโโ base/
โ โโโ deployment.yaml
โ โโโ service.yaml
โ โโโ kustomization.yaml
โ
โโโ overlays/
โโโ dev/
โ โโโ kustomization.yaml
โ
โโโ staging/
โ โโโ kustomization.yaml
โ
โโโ production/
โโโ kustomization.yamlArgo CD can point to:
overlays/productionArgo understands the Kustomize configuration and generates the desired manifests.
Argo CD can also deploy Helm charts.
Repository:
helm/
โโโ node-api/
โโโ Chart.yaml
โโโ values.yaml
โโโ templates/Argo CD points to:
helm/node-apiand can supply appropriate Helm values.
So:
Helm
โ
Kubernetes manifests
โ
Argo CD
โ
KubernetesBoth work.
Chart
+
Values
โ
Rendered resources
โ
Argo CDBase
+
Overlay
โ
Rendered resources
โ
Argo CDArgo CD becomes the GitOps controller responsible for synchronizing the resulting desired state.
Suppose:
Development
Staging
ProductionRepository:
k8s/
โ
โโโ base/
โ
โโโ overlays/
โโโ dev/
โโโ staging/
โโโ production/Then create Argo Applications:
node-api-dev
node-api-staging
node-api-productionEach points to:
different pathFor example:
node-api-dev
โ
overlays/dev
node-api-staging
โ
overlays/staging
node-api-production
โ
overlays/productionImagine you have:
20 applications
3 environmentsCreating every Argo Application manually can become repetitive.
Argo CD provides ApplicationSet for generating Applications from templates.
Conceptually:
ApplicationSet
โ
โโโ app1-dev
โโโ app1-prod
โโโ app2-dev
โโโ app2-prod
โโโ app3-dev
โโโ app3-prodThis becomes extremely useful at platform scale.
Argo CD also has:
AppProjectProjects help define boundaries such as:
Which repositories can be used?
Which clusters?
Which namespaces?
Which resource types?For example:
team-a project
โ
team-a Git repositories
โ
team-a namespacesThis provides an additional governance layer.
You now have another authorization layer.
Remember:
AWS IAM
Kubernetes RBAC
Argo CD RBACThese are different systems.
Argo CD RBAC can control:
Who can view applications?
Who can sync?
Who can modify applications?
Who can access projects?This is one of the deepest concepts in the course.
Kubernetes already does:
Desired State
โ
Controllers
โ
Actual StateGitOps adds:
Git
โ
Desired State
โ
Argo CD
โ
Kubernetes API
โ
Controllers
โ
Actual StateSo:
GitOpsis very naturally aligned with Kubernetes' controller-based architecture.
Suppose Git:
replicas: 3Cluster:
3Everything is fine.
Someone executes:
kubectl scale deployment node-api --replicas=8Now:
Git = 3
Cluster = 8Argo:
OutOfSyncIf self-healing is enabled:
8
โ
Argo reconciliation
โ
3This is GitOps in action.
Suppose:
Git
replicas: 3Developer changes:
replicas: 5and creates a pull request.
After approval:
Git
replicas: 5Argo sees:
Desired = 5
Actual = 3Then syncs:
3 โ 5This is a much more auditable deployment model.
Suppose:
Commit A
replicas: 3
Commit B
replicas: 5
Commit C
image: v2You can trace:
Git commit
โ
Configuration change
โ
Argo synchronization
โ
Kubernetes deploymentThis improves:
Suppose production is running:
v2and it is broken.
Git history:
Commit A โ v1
Commit B โ v2You can revert the deployment configuration:
Commit B
โ
revert
โ
Commit A state
โ
Argo CD
โ
Kubernetes
โ
v1This makes Git itself part of the rollback mechanism.
You now have two mechanisms.
kubectl rollout undo deployment/node-apiRevert Git commit
โ
Argo CD
โ
KubernetesWith GitOps, the Git-defined state should generally remain authoritative.
Otherwise you can create a mismatch:
Git = v2
Cluster = v1and Argo may reconcile back to v2.
Imagine:
Git says:
replicas = 3You manually execute:
kubectl scale deployment node-api --replicas=10Argo:
"Git says 3."You:
"Make it 10."Argo:
"Git says 3."This creates a fight.
The correct approach is usually:
Need 10 replicas?
โ
Change Git
โ
Review
โ
Merge
โ
Argo
โ
10 replicasFor your typical architecture:
platform-config/
โ
โโโ apps/
โ โโโ frontend/
โ โโโ backend/
โ
โโโ infrastructure/
โ โโโ redis/
โ โโโ ingress/
โ
โโโ environments/
โ
โโโ dev/
โ
โโโ staging/
โ
โโโ production/Or Kustomize:
platform-config/
โ
โโโ base/
โ โโโ frontend/
โ โโโ backend/
โ โโโ redis/
โ โโโ ingress/
โ
โโโ overlays/
โโโ dev/
โโโ staging/
โโโ production/Now combine almost everything we've learned:
Git
โ
โโโโโโโโโโโดโโโโโโโโโโ
โ โ
Application Repo Deployment Repo
โ โ
โ โ
CI Argo CD
โ โ
โ โ
Docker Image Sync
โ โ
โ โ
Registry Kubernetes
โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโ
โ โ โ
Frontend Backend Redis
โ โ
โ โ
Next.js Node.js
โ
โโโโโโโโดโโโโโโโ
โ โ
PostgreSQL RAGAnd monitoring:
Kubernetes
โ
Prometheus
โ
GrafanaLogging:
Pods
โ
Log collector
โ
Centralized loggingImagine your AI support system:
Next.js
โ
Node.js API
โ
Agent Orchestrator
โ
Retriever
โ
Vector DB
โ
LLMYou might have:
frontend Deployment
backend Deployment
retriever Deployment
worker Deployment
redis
vector DB
ingress
HPA
network policiesGitOps manages the Kubernetes configuration for all of these.
Example:
Git
โ
โโโ frontend
โโโ backend
โโโ retriever
โโโ worker
โโโ redis
โโโ ingress
โโโ HPA
โโโ network policies
โ
โ
Argo CD
โ
โ
KubernetesGit records:
Who
What
WhenYou can reconstruct environments from Git.
Cluster configuration can be compared against Git.
Infrastructure changes can go through Pull Requests.
Git history provides a natural rollback mechanism.
Developers don't necessarily need unrestricted production kubectl access.
GitOps isn't magic.
Potential challenges include:
Don't blindly commit:
password=secret123to Git.
Use:
External Secrets
Secret Manager
Sealed Secrets
SOPSor another appropriate secret-management strategy.
Very large organizations need careful repository structure.
This is especially important.
Suppose Git changes:
application v1 โ v2but database schema isn't compatible.
GitOps doesn't automatically solve migration compatibility.
You still need:
expand
โ
migrate
โ
application transition
โ
contractstrategies where appropriate.
Don't say:
"GitOps replaces CI."
That's incorrect.
A better model:
CI
โ
Build/Test/Packagewhile:
GitOps
โ
Deploy/ReconcileTogether:
CI + GitOpscan form a complete delivery system.
Strong answer:
"GitOps is an operational model where Git stores the desired state of applications and infrastructure, and an automated controller continuously reconciles the Kubernetes cluster with that state. Argo CD is a popular GitOps controller for Kubernetes."
"Argo CD is a Kubernetes continuous delivery and GitOps tool. It monitors Git repositories containing desired Kubernetes configuration, compares that configuration with the cluster, detects drift, and synchronizes the cluster according to the configured policies."
"Drift occurs when the actual state of the Kubernetes cluster differs from the desired state defined in Git."
Example:
Git:
replicas=3
Cluster:
replicas=5That's drift.
"With automated reconciliation and self-healing enabled, Argo CD can detect certain out-of-band changes and synchronize the cluster back toward the Git-defined desired state."
Answer:
"Helm packages and templates Kubernetes resources, while Argo CD acts as the GitOps controller that tracks the desired configuration and synchronizes the resulting resources to Kubernetes."
Answer:
"Kustomize manages environment-specific Kubernetes customization using bases and overlays, while Argo CD monitors the Git repository and synchronizes the rendered desired state to the cluster."
Warrior, you've now reached the point where the pieces connect:
GIT
โ
โ
CI
โ
โโโโโโโโโโโดโโโโโโโโโโ
โ โ
Tests Docker Build
โ
โ
Registry
โ
โ
Deployment Config
โ
โ
Argo CD
โ
Reconciliation
โ
โ
Kubernetes
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
Deployment Service Config
โ โ โ
โ โ ConfigMap/Secret
Pods Networking
โ โ
โโโโโโโผโโโโโโ Ingress
โ โ โ โ
Pod Pod Pod โ
Users
โ
โโโ HPA
โโโ Probes
โโโ RBAC
โโโ NetworkPolicy
โโโ Logging
โโโ Monitoring
โ
โ
Prometheus/GrafanaAnd the infrastructure:
Cloud
โ
โโโ Compute
โโโ Networking
โโโ Load Balancer
โโโ Registry
โโโ Storage
โโโ Database
โโโ IdentityGitOps
โ
Git = desired state
Argo CD
โ
GitOps controller
Sync
โ
Bring cluster toward Git state
Drift
โ
Git state โ cluster state
Self-heal
โ
Reconcile certain manual changes
Prune
โ
Remove resources no longer desired
Application
โ
Argo CD definition of a deployed application
ApplicationSet
โ
Generate many Applications
AppProject
โ
Govern Applications
Helm
โ
Package/template Kubernetes resources
Kustomize
โ
Customize Kubernetes YAML
Argo CD
โ
Deploy/reconcile Helm or Kustomize output GIT
โ
Desired State
โ
โ
ARGO CD
โ
Compare State
โ
โโโโโโโโดโโโโโโโ
โ โ
Same Different
โ โ
Synced Drift
โ
โ
Reconcile
โ
โ
KubernetesOnly Chapter 32 โ Final Production Project remains.
In the final chapter, we'll combine almost everything you've learned into one realistic system:
INTERNET
โ
โ
Ingress
โ
โโโโโโโโโโดโโโโโโโโโ
โ โ
Next.js Frontend Node.js API
โ โ
โ โโโโโโโโผโโโโโโโ
โ โ โ โ
โ Redis PostgreSQL Workers
โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
AI Services
โ
โโโโโโโโโดโโโโโโโโ
โ โ
Retriever LLM
โ
โ
Vector DBAnd around it:
Docker
Kubernetes
Helm
Kustomize
HPA
Node Autoscaling
RBAC
NetworkPolicy
Secrets
Persistent Storage
Ingress
Prometheus
Grafana
Centralized Logging
GitHub Actions
Argo CD
AWS/GCP/AzureNext โ Chapter 32: Build a Production-Style Kubernetes Application ๐
Mark it as complete to track your mastery.