Skip to main content

ArgoCD

ArgoCD is a declarative GitOps tool that continuously compares a Git repository with a Kubernetes cluster and syncs the cluster to match, correcting any drift it finds.

Understanding ArgoCD

What Is ArgoCD and How Does It Work

ArgoCD is a Kubernetes controller that implements GitOps continuous delivery. You describe the desired state of your application in Git, and ArgoCD keeps asking one question: does the live cluster match Git? If not, it marks the application OutOfSync and, depending on policy, applies the difference for you.

This pull model means your CI system never needs credentials to the cluster. Engineers deploy by merging a commit to the config repository, and the Git history becomes the audit trail of who changed what and when.

The Reconciliation Loop

flowchart LR A[(Config repo in Git)] --> B[ArgoCD controller] B --> C{Cluster matches Git?} C -->|Yes| D[Synced and Healthy] C -->|No| E[OutOfSync, apply diff] E --> D classDef store fill:#475569,color:#FFFFFF classDef tool fill:#326CE5,color:#FFFFFF classDef good fill:#10B981,color:#FFFFFF classDef warn fill:#F97316,color:#FFFFFF class A store class B,C tool class D good class E warn

ArgoCD polls Git about every three minutes by default. A webhook from GitHub or GitLab makes it react within seconds. Two separate statuses matter: sync status (does the cluster match Git?) and health status (are the resources actually working?).

Application Manifest Example

YAML
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: payment-api
namespace: argocd
spec:
project: payments
source:
repoURL: https://github.com/razorpay/k8s-configs
targetRevision: main
path: apps/payment-api/production
destination:
server: https://kubernetes.default.svc
namespace: payment-api-production
syncPolicy:
automated:
prune: true # delete resources removed from Git
selfHeal: true # revert manual kubectl changes
syncOptions:
- CreateNamespace=true

Key CLI Commands

Bash
# Create the install namespace and install ArgoCD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Inspect and compare
argocd app get payment-api
argocd app diff payment-api
# Sync manually
argocd app sync payment-api
# Roll back (auto-sync must be disabled first)
argocd app history payment-api
argocd app rollback payment-api 12

Patterns Worth Knowing

  • App of Apps: one root Application watches a folder of other Application manifests, so adding a service means adding one YAML file.
  • ApplicationSet: generates many Applications from a template, for example one per cluster or per environment folder.
  • AppProject: restricts which repos, clusters, and namespaces a team may deploy to.

Troubleshooting

Symptom Check What to Look For
Stuck OutOfSync argocd app diff Fields mutated by controllers, needs ignoreDifferences
Sync fails argocd app get --show-operation Validation or permission error message
Manual fix keeps reverting Sync policy selfHeal is working as designed
Degraded health Pod events and logs Failing probes or image pull errors
Tip

Use argocd app diff before enabling auto-sync on a production app. It shows exactly what ArgoCD would change on the first sync.

Remember

With selfHeal on, direct kubectl edits are reverted. Change Git first, even in an emergency, or pause auto-sync on that application while you work.

Security

Use AppProjects and RBAC to limit who can sync and where an Application may deploy. ArgoCD's service account holds broad cluster permissions, so write access to the config repo is effectively cluster access.

Common Mistake

Keeping application code and Kubernetes manifests in one repository. Every code commit then triggers a refresh and image-tag bumps pollute app history. Use a separate config repo.

Frequently Asked Questions

What does GitOps mean in the context of ArgoCD?

Git is the single source of truth for what runs in the cluster. You commit desired manifests, and ArgoCD reconciles the live state to match. If someone edits the cluster directly, ArgoCD detects the drift and can revert it.

Why does argocd app rollback fail on my application?

Rollback is not allowed while automated sync is enabled, because the next reconcile would immediately re-apply Git. Disable auto-sync first, or better, revert the commit in Git so the fix is recorded and applied automatically.

ArgoCD or Flux, which should I choose?

Both implement pull-based GitOps. ArgoCD offers a rich web UI, multi-cluster management, and ApplicationSets, which many teams find easier to adopt. Flux is a set of lightweight controllers that suits teams wanting a fully CLI and CRD driven workflow.

Found a mistake, an outdated step or a broken link?