GitOps Config Promotion Design: dev → staging → prod
This design outlines a GitOps-based promotion pipeline for Kubernetes configurations (e.g., Helm charts, Kustomize overlays, or raw YAML manifests). It uses Git as the single source of truth, with automated deployments via ArgoCD (primary tool; adaptable to Flux). The flow enforces gates (automated + manual) between environments and supports safe rollbacks.
Key Principles
- Environments:
dev (self-serve, fast), staging (QA/integration), prod (production).
- Repo Strategy: Single monorepo (
app-configs) with Kustomize overlays for environment-specific customization.
- Promotion: Branch-based merges/PRs (no direct pushes to protected branches).
- Gates: Pre-merge CI + post-deploy verification (automated tests + manual approvals).
- Rollbacks: Git revert + ArgoCD native rollback (zero-downtime where possible).
- Tools:
| Category | Tools |
|---|
| Git | GitHub (or GitLab) with protected branches |
| GitOps | ArgoCD (multi-cluster setup) |
| CI/CD | GitHub Actions |
| Testing | kubeval, helm lint, kyverno, custom E2E (e.g., Cypress/K6) |
| Monitoring | Prometheus + ArgoCD Notifications |
| Rollouts | Argo Rollouts (for prod blue-green/canary) |
Repository Structure
app-configs/
├── base/ # Shared manifests (e.g., Deployment, Service)
│ ├── kustomization.yaml
│ ├── deployment.yaml
│ └── configmap.yaml
├── overlays/
│ ├── dev/
│ │ ├── kustomization.yaml # Patches base for dev (e.g., replicas=1, debug=true)
│ │ └── patch-dev.yaml
│ ├── staging/
│ │ ├── kustomization.yaml # Patches for staging (e.g., replicas=3, non-prod DB)
│ │ └── patch-staging.yaml
│ └── prod/
│ ├── kustomization.yaml # Patches for prod (e.g., replicas=10, prod DB, HPA)
│ └── patch-prod.yaml
├── tests/ # Test suites (CI/E2E)
├── .github/
│ └── workflows/ # CI/CD pipelines
└── argocd-apps.yaml # ArgoCD App-of-Apps (optional)
- Branches (protected except
dev):
| Branch | Purpose | ArgoCD Target |
|---|
dev | Dev deployments (auto-merge allowed after CI) | Dev cluster/namespace |
staging | Staging deployments | Staging cluster/namespace |
main | Prod deployments | Prod cluster/namespace |
Promotion Pipeline
dev ──(PR/merge + gates)──→ staging ──(PR/merge + gates)──→ prod
▲ ▲ ▲
└────────── Git Revert ─────┘ └── Argo Rollback
1. Dev Deployment (Self-Service)
- Trigger: PR →
dev branch → merge.
- Steps:
- Developer updates
base/ or overlays/dev/.
- CI Gates (GitHub Actions):
- Lint:
kubeval, helm lint, kustomize build --validate.
- Policy: Kyverno/OPA Gatekeeper scan.
- Static tests:
conftest, custom yamllint.
- Auto-merge (optional, with required checks).
- ArgoCD: Watches
dev branch → auto-syncs to dev cluster.
- Post-Deploy Gates: Smoke tests (e.g.,
kubectl wait, basic health checks).
- Time: <5 min.
2. Dev → Staging Promotion
- Trigger: Manual PR from
dev to staging.
- Steps:
- Create PR:
git checkout -b promote/dev-to-staging dev; git push.
- Pre-Merge Gates (same CI as dev + extras):
- Diff check: Ensure no dev-specific patches leak (custom script).
- Integration tests on manifests.
- Required Approvals: 1x QA reviewer (GitHub required reviewers).
- Merge → ArgoCD syncs
staging branch to staging cluster.
- Post-Deploy Gates (ArgoCD + Notifications):
| Gate | Type | Tool |
|---|
| Smoke Tests | Auto | ArgoCD health + custom Job (e.g., curl endpoints) |
| E2E Tests | Auto | K6 load test, Cypress UI |
| Security Scan | Auto | Trivy image scan |
| Manual Approval | Manual | ArgoCD pause + Slack notification → GitHub Environment approval |
- Fail → Rollback: Auto-revert PR if post-deploy fails.
- Time: 15-30 min.
3. Staging → Prod Promotion
- Trigger: Manual PR from
staging to main.
- Steps: Identical to dev→staging, but stricter.
- Pre-Merge: + Capacity planning check (e.g., resource diffs).
- Approvals: 2x approvers (SRE + App Owner).
- Deploy via Argo Rollouts: Blue-green or canary (e.g., 20% traffic → pause → promote).
- Post-Deploy Gates:
| Gate | Type | Tool |
|---|
| Observability | Auto | Prometheus alerts (CPU<80%, error rate<1%) |
| Chaos Testing | Auto | LitmusChaos (pod kills) |
| Manual Soak | Manual | 1h observation + CAB approval (Change Advisory Board) |
- Time: 1-2 hours.
Gates Summary
- Automated (fail-fast): CI lint/policy + post-deploy smoke/E2E.
- Manual: GitHub PR approvals + ArgoCD post-sync pauses (with Slack/Teams webhooks).
- Promotion Gates Config (GitHub Actions example):
# .github/workflows/promote.yml
jobs:
promote:
environment: staging # Requires manual approval
needs: [test, lint]
- ArgoCD Gate Example (AnalysisTemplate for promotion):
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: e2e-gates
spec:
args:
- name: service-url
value: "staging-app.example.com"
metrics:
- name: k6-test
interval: 1m
successCondition: result[0].p(95) <= 200 # 95th percentile <200ms
Rollback Mechanisms
ArgoCD Setup (Multi-Cluster)
- Clusters: Separate kubeconfigs for dev/staging/prod.
- Apps:
# argocd-apps.yaml (deployed to central ArgoCD)
apiVersion: argocd.argoproj.io/v1alpha1
kind: Application
metadata:
name: myapp-dev
spec:
source:
repoURL: https://github.com/org/app-configs.git
targetRevision: dev
path: overlays/dev
destination:
server: https://dev-cluster.example.com # Cluster-specific
namespace: myapp
syncPolicy:
automated: {prune: true, selfHeal: true}
syncOptions: [Validate=true]
- Similar for staging (
targetRevision: staging) and prod (targetRevision: HEAD on main).
Monitoring & Observability
- ArgoCD Notifications: Slack/Teams for sync failures, gates.
- Dashboards: Grafana for deploy metrics (success rate, rollback freq).
- Audit: Git history + ArgoCD events.
Risks & Mitigations
| Risk | Mitigation |
|---|
| Merge Conflicts | Frequent rebases, branch protection. |
| Secret Leakage | External secrets (SealedSecrets/SecretStore). |
| Downtime in Prod | Argo Rollouts + circuit breakers. |
| Gate Bypass | Protected branches + dual approvals. |
Implementation Steps
- Set up repo + branches.
- Configure ArgoCD apps.
- Write CI workflows + tests.
- Test end-to-end: dev→staging→prod→rollback.
- Add prod gates iteratively.
This design is production-ready, scalable, and auditable. Adapt for Helm/Flux as needed! Questions?