Skip to content

Latest commit

 

History

History
102 lines (75 loc) · 2.51 KB

flux.md

File metadata and controls

102 lines (75 loc) · 2.51 KB

Flux CD

Flux is a tool that automatically ensures that the state of a cluster matches the config in git. It uses an operator in the cluster to trigger deployments inside Kubernetes, which means you don't need a separate CD tool. It monitors all relevant image repositories, detects new images, triggers deployments and updates the desired running configuration based on that (and a configurable policy).

Latest version of Flux.

Fluxs own documentation.

Example of an monorepo directory structure:

├── apps
│   ├── base
│   ├── production
│   └── development
├── infrastructure
│   ├── base
│   ├── production
│   └── development
└── clusters
    ├── production
    └── development

Configuring Flux CD

  1. Change directory to clusters/development

  2. Create infrastructure.yaml

flux create kustomization infrastructure \
    --source=GitRepository/flux-system \
    --path="./flux/infrastructure/development" \
    --prune=true \
    --interval=1m \
    --export > infrastructure.yaml
  1. Create apps.yaml which depends on infrastructure
flux create kustomization apps \
    --source=GitRepository/flux-system \
    --path="./flux/apps/development" \
    --prune=true \
    --interval=1m \
    --depends-on=infrastructure \
    --export > apps.yaml
  1. Change directory to apps/development

  2. Create kustomization.yaml

kustomize create
  1. Repeat step 5 in infrastructure/development

Adding an App from a private Git Repository

  1. Change directory to apps/base/my-app

  2. Create 'namespace.yaml' if it does not exist

kubectl create namespace my-app
  1. Create 'gitrepository.yaml'
flux create source git my-app \
    --url=ssh://git@gitlab.com:devops9483002/devops-k8s-toolkit.git \
    --branch=develop \
    --secret-ref=flux-system \
    --export > gitrepository.yaml
  1. Create 'flux-kustomization.yaml'
flux create kustomization my-app \
    --source=GitRepository/my-app.flux-system \
    --path="./k8s" \
    --prune=true \
    --interval=1m \
    --namespace=my-app-namespace \
    --export > flux-kustomization.yaml

Add flux-system in --source=GitRepository/my-app.flux-system if the GitRepository is in another namespace flux-system for this example.

  1. Create 'kustomization.yaml'
kustomize create --autodetect
  1. Commit and push changes to Git