Legacy CI/CD pipelines relied on push-based deployment scripts that executed kubectl apply commands from external CI runners directly into production clusters. This anti-pattern exposed cluster credentials to CI runners and frequently caused environment drift between Git source code and live cluster states.
**GitOps** replaces push-based deployments with a pull-based model where Git acts as the Single Source of Truth for infrastructure and application code. In this guide, we explore GitOps reconciliation loops (ArgoCD/Flux), progressive delivery strategies (Canary vs Blue-Green), and production GitHub Actions workflows.
1. The Four Core Principles of GitOps
- Declarative System Descriptions: The entire environment (Kubernetes manifests, Helm charts, Kustomize overlays) is described declaratively in Git.
- Versioned and Immutable State: Desired state is stored in Git with a complete audit log of commits, branches, and tags.
- Automated Pull-Based Sync: In-cluster agents (ArgoCD or Flux) continuously pull changes from Git and apply them to the cluster.
- Self-Healing Continuous Reconciliation: If someone manually modifies a production pod via
kubectl edit, the GitOps operator detects state drift and immediately overwrites the cluster back to the Git target state.
2. Progressive Delivery: Blue-Green vs Canary Deployments
| Deployment Strategy | Traffic Routing Mechanics | Rollback Speed & Risk Profile |
|---|---|---|
| Blue-Green Deployment | Spins up a 100% complete new environment (Green). Ingress router switches traffic from Blue to Green instantly. | Instant Rollback: Switch router back to Blue. Requires $2\times$ hardware resource capacity during deployment window. |
| Canary Deployment | Routes a small fraction of real user traffic (e.g., 5% -> 25% -> 50% -> 100%) to new version while monitoring error metrics. | Lowest Risk: Automatically aborts rollout if HTTP 5xx error rates or P99 latencies spike in Prometheus. Minimal resource overhead. |
3. Automated Canary Rollouts with Argo Rollouts & Prometheus
Tools like **Argo Rollouts** automate progressive canary deployments by querying Prometheus metrics during each step of the rollout:
4. Production GitHub Actions CI Workflow
Below is a production-grade GitHub Actions workflow that runs automated unit tests, builds a multi-arch Docker image, scans for security vulnerabilities using Trivy, and updates the GitOps manifest repository:
5. Key Takeaways for High-Velocity Engineering Teams
- Separate Source Code & Infrastructure Repositories: Keep application source code in an application repo, and Kubernetes manifests in a dedicated GitOps repository to prevent infinite CI trigger loops.
- Enforce Automated Rollbacks: Ensure canary metric analysis automatically triggers a rollback if error rates exceed 0.5% during the first 10 minutes of a release.
Join the Technical Discussion
Have questions about this architecture? Drop a comment below.