GitOps with ArgoCD
Hub › Kubernetes › Advanced › GitOps with ArgoCD
Goal
Install ArgoCD on kind and point it at a Git repository so the cluster state is declared in Git and automatically reconciled.
Prerequisites
- StatefulSet and PVC
- A GitHub/GitLab repository with your Helm chart pushed
What is GitOps
GitOps means:
The desired cluster state is declared in a Git repository. An operator (ArgoCD) continuously compares the live cluster to the repo and auto-fixes drift.
No one runs kubectl apply manually in production — the cluster pulls its config from Git.
Install ArgoCD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
kubectl -n argocd wait --for=condition=Ready pods --all --timeout=120sAccess the ArgoCD UI
# Port-forward the API server
kubectl -n argocd port-forward svc/argocd-server 8080:443 &
# Get the initial admin password
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -dOpen https://localhost:8080 in a browser, login as admin with the password above.
Install the ArgoCD CLI
brew install argocd
argocd login localhost:8080 --insecure --username adminRegister a cluster
ArgoCD needs access to your cluster:
argocd cluster add kind-kindCreate an Application
Create argocd-app.yaml:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: web-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/your-org/web-chart-repo
path: web-chart
targetRevision: HEAD
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: trueApply:
kubectl apply -f argocd-app.yamlArgoCD clones the repo, templates the Helm chart, and applies it to the cluster. The UI shows the app as Synced.
Drift detection
Delete a pod manually:
kubectl delete pod -l app=web-demo
# ArgoCD sees the drift and recreates it within secondsChange an image tag in the Git repo, commit, and push. ArgoCD detects the change and syncs automatically.
Checkpoint
argocd app list
# NAME CLUSTER NAMESPACE STATUS HEALTH
# web-app https://... default Synced Healthy
argocd app get web-app
# Shows resources, sync status, healthNext: Prometheus and Grafana — cluster monitoring and dashboards.