The user wants a blueprint for a GitOps deployment system.
This blueprint needs to cover four specific pillars:
- Drift Detection: Ensuring the live state matches the git state.
- Progressive Delivery: Rolling out changes gradually (e.g., canary/blue-green).
- Multi-Environment Promotion: Moving code from Dev -> Staging -> Prod.
- Rollbacks: Reverting to a previous state safely.
I need to structure the response as a comprehensive guide or architectural blueprint, likely involving popular tools like Argo CD or Flux, and additional tools for progressive delivery like Argo Rollouts or Flagger.
Structure of the Blueprint:
- Executive Summary/Core Philosophy: Briefly define GitOps in this context (declarative, versioned, automated).
- Tool Stack Selection: Propose a standard industry stack (e.g., Argo CD + Argo Rollouts + GitHub/GitLab).
- Architecture Diagram (Mental or Mermaid): Describe the flow.
- Pillar 1: Repository Strategy: How to organize git repos (Mono-repo vs. Multi-repo, Kustomize/Helm).
- Pillar 2: Multi-Environment Promotion: How to move between envs.
- Pillar 3: Progressive Delivery: How to update apps safely.
- Pillar 4: Drift Detection: How to prevent configuration rot.
- Pillar 5: Automated Rollbacks: What happens when things break.
- CI/CD Integration: How the pipeline triggers the GitOps operators.
Drafting the Content - Section by Section:
Refining the details:
- Drift: Mention security compliance (preventing manual
kubectl edit).
- Progressive: Mention Service Mesh (Istio/Linkerd) or Ingress (NGINX) for traffic splitting.
Formatting: Use Markdown headers, code snippets for YAML examples, and maybe a Mermaid diagram for visualization.
Self-Correction during drafting:
- Initial thought: Use Flux.
- Correction: Argo CD + Argo Rollouts is often more intuitive for "Blueprints" involving progressive delivery UIs and visualizations. Flux has Flagger, which is great, but Argo offers a slightly more cohesive ecosystem for this specific prompt. I will stick to Argo but mention that Flux is an alternative.
- Focus: Keep it practical. Don't just list features; show how to implement the logic.
Final Polish:
Ensure the distinction between Infrastructure GitOps and Application GitOps is clear, but focus on Application Deployment as requested. Ensure the "Analysis" step in progressive delivery is highlighted, as that's the "magic" sauce.
Let's write out the response following this structure.
- Architecture: High-level view.
- Repo Strategy: The foundation.
- Implementation Details (The 4 Pillars):
- Drift (Argo CD Health/Sync).
- Progressive (Argo Rollouts + Analysis).
- Promotion (Kustomize overlays + PRs).
- Rollback (Analysis failure + Git Revert).
- The Workflow Example: A step-by-step narrative.
- Code Examples: YAML snippets.
(Self-correction on Rollbacks): Make sure to distinguish between a deployment rollback (automated via Rollouts because of errors) and a code rollback (via Git).
Let's generate the response.
This blueprint outlines a production-grade GitOps architecture using Argo CD for state management and Argo Rollouts for progressive delivery. While Flux is a viable alternative, the Argo suite provides a unified custom resource definition (CRD) ecosystem that simplifies the setup of Rollouts and Analysis.
1. Architecture Overview
We will use a Multi-Cluster / Hub-and-Spoke topology.
- Management Cluster: Hosts the GitOps Controllers (Argo CD) and the Rollouts Dashboard.
- Workload Clusters: Dev, Staging, and Production where the actual applications run.
- Git Layout: We will use a Mono-repo approach for simplification, though this logic applies to multi-repo structures.
The Stack:
- GitOps Engine: Argo CD
- Progressive Delivery: Argo Rollouts
- Templating: Kustomize (for environment manifests)
- Traffic Management: Nginx Ingress (or Istio/Service Mesh for advanced traffic splitting)
- Metric Analysis: Prometheus
2. Repository Structure
This structure separates the source code (not shown) from the deployment configuration.
├── apps/
│ └── my-app/
│ ├── base/ # Generic Kubernetes manifests
│ │ ├── deployment.yaml # NOTE: Replaced by Rollout CRD
│ │ ├── service.yaml
│ │ └── kustomization.yaml
│ └── overlays/
│ ├── dev/
│ │ └── kustomization.yaml
│ ├── staging/
│ │ └── kustomization.yaml
│ └── production/
│ ├── kustomization.yaml
│ └── rollout.yaml # Specific Progressive Delivery logic
├── argo-apps/ # Argo CD Application Definitions
│ ├── dev.yaml
│ ├── staging.yaml
│ └── prod.yaml
└── workflows/ # Promotion logic (optional automation)
3. Pillar 1: Drift Detection & Correction
Drift occurs when the live cluster state differs from Git (e.g., someone ran kubectl edit manually).
Implementation:
In Argo CD, we define the Application with an automated sync policy. This ensures that if manual changes are made, the GitOps controller overwrites them to match the "Single Source of Truth" (Git).
File: argo-apps/prod.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: prod-my-app
namespace: argocd
spec:
project: default
source:
repoURL: 'https://github.com/my-org/gitops-repo.git'
targetRevision: main
path: apps/my-app/overlays/production
destination:
server: 'https://prod-cluster-api-url'
namespace: my-app
syncPolicy:
automated:
prune: true # Deletes resources that are no longer in Git
selfHeal: true # Overrides manual changes (Drift Correction)
syncOptions:
- CreateNamespace=true
4. Pillar 2: Progressive Delivery (Canary)
We replace the standard Kubernetes Deployment with the Argo Rollouts Rollout CRD. This allows us to manage traffic splitting and gradual updates.
File: apps/my-app/overlays/production/rollout.yaml
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: my-app
spec:
replicas: 10
revisionHistoryLimit: 2
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-registry/my-app:v1.0.0
ports:
- containerPort: 8080
# The Strategy defines the Progressive Delivery
strategy:
canary:
steps:
- setWeight: 10 # Route 10% of traffic to the new version
- pause: {duration: 2m} # Wait 2 minutes to observe logs/metrics
- setWeight: 40
- pause: {duration: 2m}
- setWeight: 80
- pause: {duration: 2m}
5. Pillar 3: Automated Analysis (The "Fail Fast" Mechanism)
To truly automate progressive delivery, we must verify the canary is healthy before promoting it to 100%. We use the AnalysisTemplate to query Prometheus.
File: apps/my-app/base/analysis-template.yaml
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: error-rate-analysis
spec:
args:
- name: service-name
metrics:
- name: error-rate
interval: 60s
successCondition: result[0] <= 0.01 # Fail if error rate > 1%
failureLimit: 1
provider:
prometheus:
address: http://prometheus.monitoring.svc.cluster.local:9090
query: |
sum(rate(http_requests_total{status=~"5.*",service="{{args.service-name}}"}[5m]))
/
sum(rate(http_requests_total{service="{{args.service-name}}"}[5m]))
Updated Rollout Strategy (Hooking Analysis):
strategy:
canary:
steps:
- setWeight: 20
- analysis:
templates:
- templateName: error-rate-analysis
args:
- name: service-name
value: my-app
6. Pillar 4: Multi-Environment Promotion
Promotion is the act of moving a validated version of code from one environment to the next. We use Kustomize to overlay environment-specific configs and automate the image tag updates.
The Promotion Workflow:
- Dev Deployment: CI Pipeline updates the image tag in
apps/my-app/overlays/dev/kustomization.yaml. Argo CD syncs immediately.
- Staging Promotion: Once QA approves Dev, a script or GitHub Action patches
apps/my-app/overlays/staging/kustomization.yaml with the new tag.
- Production Promotion: The critical step.
- Automated Approach: A CI job identifies the tag currently in Staging and opens a Pull Request to update
apps/my-app/overlays/production/kustomization.yaml.
- Manual Gate: The PR requires approval from a Lead Engineer.
- Merge: Upon merge, Argo CD detects the change and triggers the
Rollout strategy defined in Pillar 2.
Example Kustomize Overlay (overlays/prod/kustomization.yaml):
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
images:
- name: my-registry/my-app
newTag: v1.0.0 # This is the value changed during promotion
7. Pillar 5: Automated Rollbacks
There are two types of rollbacks in this architecture:
A. Immediate Analysis Rollback (Automated)
If the AnalysisTemplate (defined in Pillar 3) fails (e.g., error rate spikes to 50%), Argo Rollouts automatically:
- Stops the rollout.
- Scales the "Canary" pods to 0.
- Routes 100% traffic back to the stable "Active" pods.
- Marks the Rollout as "Degraded."
B. Git-Based Rollback (Manual)
If a bug is found days later (not detected by metrics):
- Identify the last known good Git Commit SHA.
- Execute
git revert <sha> or git checkout <sha>.
- Argo CD detects the state drift (Old state vs New Bad State).
- Argo CD performs a
Sync, deploying the old binaries to the cluster.
Summary Checklist
| Feature | Technology | Mechanism |
|---|
| Drift Detection | Argo CD | selfHeal: true in SyncPolicy. |
| Progressive Delivery | Argo Rollouts | Canary Strategy with setWeight and pause. |
| Analysis | Argo Rollouts + Prometheus | AnalysisTemplate querying error rates. |
| Multi-Env Promotion | Kustomize + CI Pipeline | Patching image tags in overlay files sequentially. |
| Rollbacks | Argo Rollouts / Git | Auto-rollback on Analysis failure OR Git Revert. |