fluxcd / flux-kustomize-example

Flux v1: Example of Flux using manifest generation with Kustomize
Apache License 2.0
76 stars 111 forks source link
flux gitops kubernetes kustomize

Using Flux with Kustomize

We are moving to Flux v2

⚠️ Please note: In preparation of Flux v2 GA this repository with Flux v1 examples has been archived. The Flux v2 equivalent of what is shown here can be found at flux2-kustomize-helm-example.

Thanks a lot for your interest.

For posterity

Scenario and Goals

The following example makes use of Flux's manifest-generation feature together with Kustomize (and other such tooling, in theory).

For this example we assume an scenario with two clusters, staging and production. The goal is to levarage the full functionality of Flux (including automatic releases and supporting all fluxctl commands) to manage both clusters while minimizing duplicated declarations.

staging and production are almost identical, they both deploy a podinfo service. However, we have different requirments for each cluster:

  1. We want automated deployments for staging but not for production since we want a rubber-stamp every change. However, we want to still be able to make the changes with fluxctl.
  2. Since we expect production to have a higher load than staging, we want a higher replica range there.

How to run the example

In order to run this example, you need to:

  1. Deploy Flux version 1.13.0 or newer.

  2. Make sure to pass the flag --manifest-generation=true to fluxd, in its container spec.

  3. Fork this repository and add the fork's URL as the --git-url flag for the fluxd container.

  4. Pick an environment to run (staging or production) and ask Flux to use that environment by passing flag --git-path=staging or --git-path=production

  5. As usual, you need to make sure that the ssh key shown by fluxctl identity is added to the your github fork.

How does this example work?

├── .flux.yaml
├── base
│   ├── demo-ns.yaml
│   ├── kustomization.yaml
│   ├── podinfo-dep.yaml
│   ├── podinfo-hpa.yaml
│   └── podinfo-svc.yaml
├── staging
│   ├── flux-patch.yaml
│   └── kustomization.yaml
└── production
    ├── flux-patch.yaml
    ├── kustomization.yaml
    └── replicas-patch.yaml

I want to know more

For a more sophisticated example of using Flux with Kustomize for creating a multitenant cluster you can go to https://github.com/fluxcd/multi-tenancy .

For more details about how .flux.yaml files work you can read the reference documentation