Kubernetes GitOps with ArgoCD: A Practical Guide
DevOpsKubernetes
kubernetesgitopsargocdcontinuous-deployment
Kubernetes GitOps with ArgoCD: A Practical Guide
GitOps transforms infrastructure management by making Git the single source of truth. ArgoCD implements GitOps for Kubernetes with a powerful UI and automation capabilities.
Why GitOps?
Traditional CI/CD pipelines push changes to clusters. GitOps inverts this:
- Pull-based: Clusters pull their desired state from Git
- Declarative: Describe what you want, not how to get there
- Versioned: Every change is tracked in Git
- Auditable: Full history of who changed what and when
ArgoCD Setup
Installation
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Access the UI
kubectl port-forward svc/argocd-server -n argocd 8080:443
Application Configuration
Basic Application
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/org/my-app
targetRevision: main
path: k8s
destination:
server: https://kubernetes.default.svc
namespace: my-app
syncPolicy:
automated:
prune: true
selfHeal: true
Multi-Cluster Setup
spec:
destination:
server: https://cluster-2.example.com
namespace: production
Sync Strategies
Automatic Sync
syncPolicy:
automated:
prune: true # Delete resources not in Git
selfHeal: true # Revert manual changes
Manual Sync with Hooks
hooks:
- name: PreSync
type: PreSync
command: ["sh", "-c", "run-migrations.sh"]
Rollback Strategy
ArgoCD makes rollbacks trivial:
# List history
argocd app history my-app
# Rollback to previous
argocd app rollback my-app 1
Best Practices
- One app per repository or use monorepo with clear paths
- Separate environments via branches or kustomize overlays
- Use ApplicationSets for multi-cluster deployments
- Enable notifications for sync failures
- Implement RBAC for team access control
Conclusion
ArgoCD brings declarative, version-controlled deployments to Kubernetes. Start simple, add complexity as needed, and always test rollbacks.