Advanced 26 min readModule: Module 14: GitOps & Declarative Delivery: ArgoCD & Helm
GitOps Continuous Delivery: ArgoCD, Helm & Self-Healing
Implement modern GitOps delivery pipelines: Git as the single source of truth, ArgoCD Application controller architecture, Kustomize environment overlays (dev/stage/prod), automated drift detection, and self-healing cluster synchronization.
What You Will Learn in This Lesson
- The 4 principles of OpenGitOps: Declarative, Versioned & Immutable, Pulled Automatically, Continuously Reconciled
- Why Push CI/CD pipelines (running `kubectl` from Jenkins/GitHub Actions) expose critical security credentials
- Configuring ArgoCD Applications with automated sync policies, prune, and selfHeal
- Managing multi-environment Kubernetes configurations using Kustomize overlays
Introduction & Core Concept
In traditional Push-based CI/CD pipelines, build runners in CI (GitHub Actions, Jenkins) require cluster-admin credentials to execute `kubectl apply` directly against production Kubernetes. In the GitOps paradigm, Git is the single source of truth for desired infrastructure state. An in-cluster Pull agent (ArgoCD) continuously monitors Git, detects configuration drifts, and reconciles the cluster to match Git automatically—with zero cluster credentials ever leaving the private network.
WHY DOES THIS MATTER IN THE REAL WORLD?
GitOps provides instant rollbacks via `git revert`, prevents manual configuration drift (hotfixes overridden by CI), and provides a cryptographic audit log of every infrastructure change.
Syntax & Structure
yaml
apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: name: payment-servicespec: syncPolicy: automated: prune: true selfHeal: trueArgoCD Declarative Application Manifest with Automated Self-Healing
yamlyaml
123456789101112131415161718192021222324252627282930# Declarative ArgoCD Application Manifest (GitOps Single Source of Truth)apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata:name: kwas-core-platformnamespace: argocdfinalizers:- resources-finalizer.argocd.argoproj.iospec:project: defaultsource:repoURL: 'https://github.com/kwas-academy/infrastructure-gitops.git'targetRevision: main # Git branch / commit SHA / Helm tagpath: environments/production # Path to Kustomize overlaysdestination:server: 'https://kubernetes.default.svc' # Target In-Cluster API Servernamespace: productionsyncPolicy:automated:prune: true # Deletes resources from K8s if removed from Git reposelfHeal: true # Automatically reverts any manual 'kubectl edit' changes!syncOptions:- CreateNamespace=true- ApplyOutOfSyncOnly=trueretry:limit: 5backoff:duration: 5sfactor: 2maxDuration: 3m
Line-by-Line Technical Breakdown
1App of Apps Pattern: In enterprise setups, rather than managing 100 individual ArgoCD application YAMLs, teams deploy an 'App of Apps'—a single root ArgoCD Application that points to a folder containing other Application manifests, automating multi-cluster bootstrapping.
Try It Yourself (Interactive Editor)
Modify the code in real-time and click Run to test live browser output and console logs.
Intelligent Code Runner & Live Sandbox[YAML]
YAML SOURCE EDITOR
Interactive Live CodeCommon Mistakes & How to Avoid Them
#1: Storing plain-text database secrets in GitOps repositories without cryptographic encryption.
Base64 is encoding, not encryption. Always use SealedSecrets or External Secrets Operator so only encrypted ciphertexts are committed to Git.
Incorrect / Antipattern
apiVersion: v1
kind: Secret
data:
DB_PASS: cGFzc3dvcmQxMjM= # Decodable base64 in Git!Correct / Professional Solution
# Use SealedSecrets (Bitnami) or External Secrets Operator with HashiCorp Vault / AWS Secrets ManagerIndustry Best Practices & Professional Standards
- Enable `selfHeal: true` and `prune: true` in production ArgoCD applications.
- Use Kustomize overlays to share base YAML configurations across dev, staging, and prod.
- Deploy External Secrets Operator to securely inject secrets from AWS KMS or HashiCorp Vault.
Lesson Summary & Core Takeaways
- GitOps uses Git as the declarative, auditable single source of truth for infrastructure.
- ArgoCD pulls changes from Git, preventing cluster credential exposure in CI systems.
- Automated drift detection and self-healing prevent undocumented configuration drifts.