GitOps for Application Environments

CNPA Domain: Continuous Delivery & Platform Engineering (16%) Topic: GitOps for Application Environments

Overview

Applying GitOps to manage multiple application environments β€” dev, staging, production, preview β€” is one of the highest-value use cases for platform engineering. When every environment is a Git-declared state, promotion between environments is a controlled, auditable process rather than a risky manual procedure.


Environment Promotion with GitOps

The central challenge of multi-environment delivery is promotion: moving a verified artifact from one environment to the next with confidence.

CI Pipeline produces image:
  registry.example.com/payment-service:abc1234

GitOps Promotion Flow:
  [staging manifests] ──PR merge──▢ [staging cluster reconciles]
          ↓ (tests pass + approval)
  [production manifests] ──PR merge──▢ [production cluster reconciles]

All promotions are Git pull requests β€” reviewable, reversible, traceable.


Repository Structure for Multi-Environment GitOps

Environment Directory Pattern

Image Update per Environment


Automated Image Promotion

Flux Image Automation

Flux can automatically update image tags in Git when a new image is pushed to the registry:

This commits updated image tags back to Git automatically β€” keeping the repo as the true source of deployment history.


Progressive Delivery

GitOps integrates naturally with progressive delivery strategies that reduce deployment risk.

Deployment Strategies

Strategy
How
Risk
Rollback

Recreate

Stop old, start new

Downtime

New deploy

Rolling Update

Replace pods gradually

Low

kubectl rollout undo

Blue/Green

Run both versions, switch traffic

Low

Switch back instantly

Canary

Route % of traffic to new version

Very Low

Reduce canary to 0%

Argo Rollouts (Canary via GitOps)

If the analysis step fails (e.g., error rate > threshold), the rollout automatically aborts and rolls back.


Preview Environments via GitOps

Preview environments are ephemeral environments created for each pull request.

PR Preview Workflow


Multi-Cluster GitOps

Platform teams often manage GitOps across multiple clusters (per environment, per region, per tenant).

Fleet Management with ArgoCD ApplicationSets

A single ApplicationSet manages all environments β€” add a new cluster by adding one list entry.


GitOps Promotion Policies

Mature platform engineering teams define promotion policies enforced through Git branch protection and CI checks:

Policy
Enforcement

All staging tests must pass before production PR

CI status check required on GitOps repo

Production changes require 2 approvals

Branch protection rule

No direct commits to production directory

CODEOWNERS file

Image tags must be immutable SHA-based

Policy check in CI


Key Takeaways

  • GitOps turns environment promotion into an auditable Git workflow: PR β†’ review β†’ merge β†’ reconcile

  • Use a centralized GitOps repo with per-environment directories managed by the platform team

  • Flux image automation can auto-commit new image tags to keep Git in sync with the registry

  • Progressive delivery (canary, blue/green) with Argo Rollouts integrates naturally with GitOps for safer deployments

  • Preview environments are ephemeral namespaces created and destroyed via GitOps per pull request

  • ApplicationSets in ArgoCD enable fleet-wide multi-cluster GitOps with minimal configuration


Further Reading

Last updated