What Is Argo CD?
Argo CD is the most popular GitOps continuous delivery tool for Kubernetes. It watches Git repos and syncs desired state to clusters. 18K+ GitHub stars, CNCF Graduated.
GitOps Principle
Git (desired state) ββsyncβββΆ Kubernetes (actual state)
β β
ββββ Argo CD reconciles ββββββββ
every 3 minutesInstallation
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Get initial admin password
argocd admin initial-password -n argocdApplication Definition
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: payment-service
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/myorg/payment-service
targetRevision: main
path: k8s/production
destination:
server: https://kubernetes.default.svc
namespace: payments
syncPolicy:
automated:
prune: true # Delete resources removed from Git
selfHeal: true # Fix manual changes in cluster
syncOptions:
- CreateNamespace=true
- PrunePropagationPolicy=foreground
retry:
limit: 5
backoff:
duration: 5s
maxDuration: 3mApplicationSets (Multi-Cluster/Multi-Env)
Deploy to multiple environments from a single definition:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: payment-service
spec:
generators:
- list:
elements:
- cluster: production
url: https://prod-cluster.example.com
namespace: payments
values:
replicas: "3"
- cluster: staging
url: https://staging-cluster.example.com
namespace: payments
values:
replicas: "1"
template:
metadata:
name: "payment-{{cluster}}"
spec:
source:
repoURL: https://github.com/myorg/payment-service
path: "k8s/{{cluster}}"
destination:
server: "{{url}}"
namespace: "{{namespace}}"
syncPolicy:
automated:
selfHeal: trueProgressive Delivery
Canary with Argo Rollouts
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: payment-service
spec:
replicas: 5
strategy:
canary:
steps:
- setWeight: 10 # 10% traffic to new version
- pause: {duration: 5m}
- analysis: # Run metrics check
templates:
- templateName: success-rate
- setWeight: 50 # 50% if analysis passes
- pause: {duration: 10m}
- analysis:
templates:
- templateName: success-rate
# Full rollout if all analyses passNotifications
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
trigger.on-sync-failed: |
- when: app.status.sync.status == 'OutOfSync'
send: [slack-alert]
template.slack-alert: |
message: |
Application {{.app.metadata.name}} sync failed!
{{.app.status.sync.status}}
service.slack: |
token: $slack-token
channel: deploymentsBest Practices
- Separate app repos from config repos β donβt mix code and K8s manifests
- Use Helm or Kustomize β not raw YAML (too many files)
- Enable auto-sync + self-heal β manual sync defeats GitOps
- ApplicationSets for scale β donβt create Applications manually
- RBAC per team β projects restrict what teams can deploy where
- Notifications β alert on sync failures immediately