How to set up GitOps with Argo CD
Deploy applications to Kubernetes declaratively by syncing manifests from Git with Argo CD. Covers installation, Applications, automated sync, and drift correction.
What and why
GitOps treats a Git repository as the single source of truth for infrastructure and applications. Argo CD is a Kubernetes controller that continuously compares the cluster to Git and reconciles differences. This tutorial deploys an app from Git and watches Argo CD heal drift.
Prerequisites
- A running Kubernetes cluster.
kubectlconfigured to reach it.- A Git repository containing Kubernetes manifests.
Steps
1. Install Argo CD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
This installs the controller, repo server, and API server.
2. Access the API and UI
kubectl port-forward svc/argocd-server -n argocd 8080:443
Log in with the admin user; the initial password is stored in a secret named argocd-initial-admin-secret.
3. Prepare a Git repo of manifests
Put your Deployment and Service YAML under a path such as apps/web/. This path is what Argo CD will track.
4. Create an Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: web
namespace: argocd
spec:
source:
repoURL: https://github.com/acme/manifests
path: apps/web
targetRevision: main
destination:
server: https://kubernetes.default.svc
namespace: web
Apply it with kubectl apply -f.
5. Enable automated sync
syncPolicy:
automated:
prune: true
selfHeal: true
selfHeal reverts manual cluster changes; prune removes resources deleted from Git.
Verification
In the UI the Application should report Synced and Healthy. Manually edit the live Deployment with kubectl scale. Within moments Argo CD detects drift and restores the Git-defined value, proving self-healing.
Next Steps
Manage many apps with an app-of-apps pattern. Combine with Helm or Kustomize for templating. Restrict who can change manifests via repository review rules, since Git access now equals deploy access.
Prerequisites
- A running Kubernetes cluster
- kubectl configured
- A Git repo with manifests
Steps
- 1Install Argo CD
- 2Access the API and UI
- 3Prepare a Git repo of manifests
- 4Create an Application
- 5Enable automated sync
- 6Verify drift correction