Code Monkey home page Code Monkey logo

flux-kustomize-example's Introduction

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
  • base contains the base manifests. The resources to be deployed in staging and production are almost identical to the ones described here.
  • the staging and production directories make use of base, with a few patches, to generate the final manifests for each environment:
    • staging/kustomization.yaml and production/kustomization.yaml are Kustomize config files which indicate how to apply the patches.
    • staging/flux-patch.yaml and production/flux-patch.yaml contain environment-specific Flux annotations and the container images to be deployed in each environment.
    • production/replicas-patch.yaml increases the number of replicas of podinfo in production.
  • .flux.yaml is used by Flux to generate and update manifests. Its commands are run in the directory (staging or production). In this particular case, .flux.yaml tells Flux to generate manifests running kustomize build and update policy annotations and container images by editing flux-patch.yaml, which will implicitly applied to the manifests generated with kustomize build.

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

flux-kustomize-example's People

Contributors

2opremio avatar benjaminherbert avatar dschulten avatar fabian-k avatar hiddeco avatar squaremo avatar stealthybox avatar stefanprodan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flux-kustomize-example's Issues

Flux Git Write Overwrites Patch

When I deployed this, the first time flux tried to update an image version automatically, it completely overwrote the flux-patch.yaml with nothing but that image tag update.

Kustomize: Istio installation error

├── base
│ ├── kustomization.yaml
│ └── istio.yaml
└── Dev
| └── kustomization.yaml
├── Prod
|── kustomization.yaml

This is my Kustomise folder structure, i have kept the istio in base. base.kustomisation yaml has istio.yaml reference.

When i try to build in dev or prod ( kustomise build . ) in locally ,I get the below error

this is giving below error -
webhooks.clientConfig.service ignored in mutation attempt

When i remove the istio.yaml file and run command kustomise build . in local it works fine.

istio.yaml.txt

Note: Kustomize need to be apply cluster via flux-cd.

component=sync-loop err="loading resources from repo: duplicate definition of 'demo:deployment/podinfo'

Forked repo to my github account

Installed flux using below command -
helm upgrade -i flux fluxcd/flux --set [email protected]:nikhilbalekundargi/flux-kustomize-example.git --set manifest-generation=true --set git-path=staging --set syncGarbageCollection.enabled=true --namespace flux --set helm.versions=v3 --wait
Added the deploy keys.

But getting below error -

ts=2020-06-29T11:39:45.025457267Z caller=loop.go:133 component=sync-loop event=refreshed url=ssh://[email protected]/nikhilbalekundargi/flux-kustomize-example.git branch=master HEAD=6afd0470c3e3638e6be049e4cc092f5181cd4f40
ts=2020-06-29T11:39:45.078872121Z caller=sync.go:73 component=daemon info="trying to sync git changes to the cluster" old= new=6afd0470c3e3638e6be049e4cc092f5181cd4f40
ts=2020-06-29T11:39:45.085088452Z caller=loop.go:107 component=sync-loop err="loading resources from repo: duplicate definition of 'demo:deployment/podinfo' (in base/podinfo-dep.yaml and production/flux-patch.yaml)"

fluxcd/flux#3166

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.