GitOps · · 3 min read

GitOps: Episode Four — Managing Multi-Environment Deployments with GitOps

Learn how to manage dev, staging, and production environments with GitOps. Structure your repos for clean, automated multi-env deployments.

Managing Multi-Environment Deployments with GitOps
Photo by Desola Lanre-Ologun / Unsplash

In the last post, we successfully deployed our first application with GitOps. Now it’s time to take things a step further and handle a real-world scenario: managing multiple environments like development, staging, and production.

In any serious project, separating environments is essential for testing new features safely, validating them, and then promoting them to production. GitOps gives us a clean, automated, and auditable way to manage this process — all through Git commits.

Let’s dive into how to structure, configure, and automate multi-environment deployments using GitOps.

1. Why Manage Multiple Environments with GitOps?

In simple setups, deploying directly to production might seem fast. But as soon as teams grow or applications become critical, having isolated environments becomes essential.

In a traditional workflow, teams might manually update dev, staging, and prod clusters by hand or through scripts. Unfortunately, this manual process often leads to:

GitOps offers a better solution. By treating environments as code — stored, versioned, and managed in Git — teams gain:

Instead of relying on memory or tradition, we make environments predictable and repeatable.


2. Structuring the Git Repository for Multiple Environments

The way you organize your Git repository plays a major role in successful multi-environment GitOps.

A clean structure could look like this:

your-repo/
└── clusters/
    ├── dev/
    │   ├── apps/
    │   └── kustomization.yaml
    ├── staging/
    │   ├── apps/
    │   └── kustomization.yaml
    └── prod/
        ├── apps/
        └── kustomization.yaml

Each environment — dev, staging, and prod — has its own directory. Inside each, you’ll define the applications, configurations, and resources specific to that environment.

This separation provides two big advantages:

It’s worth noting that while the application itself might stay the same, each environment could have small differences — like the number of replicas, feature flags, or resource limits — all controlled in their respective directories.


3. Setting Up Kustomizations for Each Environment

Once we have our folder structure in Git, we need to teach Flux how to handle it. We do that using Kustomizations.

In GitOps, a Kustomization defines:

Here’s an example Kustomization for the dev environment:

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: dev
  namespace: flux-system
spec:
  interval: 5m0s
  path: ./clusters/dev
  prune: true
  sourceRef:
    kind: GitRepository
    name: flux-system

We would create similar Kustomizations for staging and prod, adjusting the path and name accordingly.

By defining a Kustomization per environment, Flux will treat each one independently:

Each environment can sync at its own pace and on its own terms.


4. Deployment Flow: From Dev to Production

Managing multiple environments also changes how deployments happen.

Instead of applying changes manually, the deployment process becomes a series of Git operations:

  1. Developers commit changes into the dev environment directory.
  2. Flux syncs those changes and deploys to the dev cluster automatically.
  3. After testing and validation, a pull request promotes the exact same configuration to the staging environment.
  4. After additional testing in staging, another pull request promotes it to production.

Each promotion step involves no cluster commands, just Git operations. This brings:

This approach also encourages review culture: before something reaches production, it must pass through dev and staging, with peer reviews at each step.


5. What’s Next

Now that we have our environments separated and a promotion workflow mapped out, we’re almost ready for more powerful setups.

In the next post, we’ll explore how to use Helm charts with GitOps:

GitOps is starting to feel real now — and you’re building serious, production-grade skills step-by-step.


Previous Posts in the Series


Enjoying this journey into GitOps?

Subscribe to get future episodes, real-world tutorials, and in-depth guides delivered right to your inbox!

Read next