Difference between revisions of "Kubernetes/Progressive Delivery Flux and Flagger"

From Ever changing code
Jump to navigation Jump to search
 
(22 intermediate revisions by the same user not shown)
Line 1: Line 1:
= [https://docs.fluxcd.io/en/latest/references/fluxctl/ Flux] =
= [https://github.com/fluxcd/flux2 Flux v2] =
Flux v2 architecture
Flux v2 architecture
:[[File:ClipCapIt-210524-232835.PNG]]
:[[File:ClipCapIt-210524-232835.PNG]]
Line 7: Line 7:




Docs:
* [https://fluxcd.io/docs/ Flux v2 Documentation]
= Install Flux v2 [https://fluxcd.io/docs/cmd/ <code>flux</code>] command line =
* [https://fluxcd.io/docs/get-started/ Fluxv2 Get Started]


Install Flux v2 <code>flux</code> command line


{{Note|<code>fluxctl</code> is a previous version Flux v1 command line tool.}}
{{Note|<code>fluxctl</code> is a previous version Flux v1 command line tool.}}
<source lang=bash>
<source lang=bash>
curl -s https://fluxcd.io/install.sh | sudo bash
# Install or upgrade using official install.sh (option-1)
export FLUX_VERSION=0.37.0; curl -s https://fluxcd.io/install.sh | sudo -E bash
curl -s https://fluxcd.io/install.sh | sudo bash # latest
 
# Install from GitHub releases (option-2)
REPO=fluxcd/flux2
LATEST=$(curl --silent "https://api.github.com/repos/$REPO/releases/latest" | jq -r .tag_name | tr -d v); echo $LATEST
VERSION=$LATEST
TEMPDIR=$(mktemp -d); FILE=flux_${VERSION}_linux_amd64
curl -L https://github.com/$REPO/releases/download/v${VERSION}/$FILE.tar.gz -o $TEMPDIR/$FILE.tar.gz
tar xzvf $TEMPDIR/$FILE.tar.gz -C $TEMPDIR
sudo install $TEMPDIR/flux /usr/local/bin/flux
sudo install $TEMPDIR/flux /usr/local/bin/flux_${VERSION}


# enable completions in ~/.bash_profile
# enable completions in ~/.bash_profile
Line 23: Line 39:
flux check --pre
flux check --pre
► checking prerequisites
► checking prerequisites
✔ kubectl 1.18.6 >=1.18.0-0
✗ flux 0.25.1 <0.25.2 (new version is available, please upgrade)
✔ Kubernetes 1.18.9 >=1.16.0-0
✔ Kubernetes 1.21.5-gke.1302 >=1.19.0-0
✔ prerequisites checks passed
✔ prerequisites checks passed
# Docker images
docker pull fluxcd/fluxctl:1.24.3
docker pull ghcr.io/fluxcd/flux-cli:1.24.3 # does not work
</source>
</source>


Cluster bootstrap
= Cluster bootstrap =
FluxCDv2 bootstrap process is installing the Flux onto a cluster and stores(commits) its own manifests to a Git repository.
* [https://fluxcd.io/docs/installation/#generic-git-server Generic Git Server], including GCP [https://cloud.google.com/source-repositories/docs Cloud Source Repositories]
* [https://fluxcd.io/docs/installation/#bootstrap-with-terraform Bootstrap with Terraform]
 
 
<source lang=bash>
<source lang=bash>
FLUX_GIT_USERNAME=my-git-username
FLUX_GIT_USERNAME=my-git-username
Line 39: Line 64:
</source>
</source>
At bootstrap, Flux generates an SSH key and prints the public key. In order to sync your cluster state with git you need to copy the public key and create a deploy key with write access on your GitHub repository. On GitHub go to Settings > Deploy keys click on Add deploy key, check Allow write access, paste the Flux public key and click Add key.
At bootstrap, Flux generates an SSH key and prints the public key. In order to sync your cluster state with git you need to copy the public key and create a deploy key with write access on your GitHub repository. On GitHub go to Settings > Deploy keys click on Add deploy key, check Allow write access, paste the Flux public key and click Add key.
;[https://fluxcd.io/docs/installation/#dev-install Dev installation] does not stores its own configuration state in Git repository
<source lang=bash>
# option 1
flux install # install and upgrade
flux install \
--namespace=flux-system \
--network-policy=false \
--components=source-controller
# option 2
kubectl apply -f https://github.com/fluxcd/flux2/releases/latest/download/install.yaml
kustomize build https://github.com/fluxcd/flux2/manifests/install?ref=main | kubectl apply -f- # Upgrade
# Register Git repositories and reconcile them on your cluster:
flux create source git podinfo \
  --url=https://github.com/stefanprodan/podinfo \
  --tag-semver=">=4.0.0" \
  --interval=1m
flux create kustomization podinfo-default \
  --source=podinfo \
  --path="./kustomize" \
  --prune=true \
  --validation=client \
  --interval=10m \
  --health-check="Deployment/podinfo.default" \
  --health-check-timeout=2m
# Register Helm repositories and create Helm releases:
flux create source helm bitnami \
  --interval=1h \
  --url=https://charts.bitnami.com/bitnami
flux create helmrelease nginx \
  --interval=1h \
  --release-name=nginx-ingress-controller \
  --target-namespace=kube-system \
  --source=HelmRepository/bitnami \
  --chart=nginx-ingress-controller \
  --chart-version="5.x.x"
</source>
Uninstall
<source lang=bash>
flux uninstall --namespace=flux-system
</source>


= References =
= References =
* [https://github.com/fluxcd/terraform-provider-flux terraform-provider-flux]
*[https://github.com/pio2pio/gitops-istio gitops-istio] Tutorial
*[https://github.com/pio2pio/gitops-istio gitops-istio] Tutorial
*[https://www.youtube.com/watch?v=nGLpUCPX8JE Flux v2 Everything that you wanted to know but were afraid to ask (Stefan Prodan)] December 2020
Bundle
*[https://blog.sldk.de/2021/02/introduction-to-gitops-on-kubernetes-with-flux-v2/ Introduction to GitOps on Kubernetes with Flux v2]
*[https://blog.sldk.de/2021/03/handling-secrets-in-flux-v2-repositories-with-sops/ Handling secrets in Flux v2 repositories with SOPS]

Latest revision as of 15:26, 4 January 2024

Flux v2

Flux v2 architecture

ClipCapIt-210524-232835.PNG

Flux v2 - Webhooks and notifications

ClipCapIt-210524-233028.PNG


Docs:

Install Flux v2 flux command line


Note: fluxctl is a previous version Flux v1 command line tool.

# Install or upgrade using official install.sh (option-1)
export FLUX_VERSION=0.37.0; curl -s https://fluxcd.io/install.sh | sudo -E bash
curl -s https://fluxcd.io/install.sh | sudo bash # latest

# Install from GitHub releases (option-2)
REPO=fluxcd/flux2
LATEST=$(curl --silent "https://api.github.com/repos/$REPO/releases/latest" | jq -r .tag_name | tr -d v); echo $LATEST
VERSION=$LATEST
TEMPDIR=$(mktemp -d); FILE=flux_${VERSION}_linux_amd64
curl -L https://github.com/$REPO/releases/download/v${VERSION}/$FILE.tar.gz -o $TEMPDIR/$FILE.tar.gz
tar xzvf $TEMPDIR/$FILE.tar.gz -C $TEMPDIR
sudo install $TEMPDIR/flux /usr/local/bin/flux
sudo install $TEMPDIR/flux /usr/local/bin/flux_${VERSION}

# enable completions in ~/.bash_profile
. <(flux completion bash)

# TODO: Via release binaries
# https://github.com/fluxcd/flux/releases

# Pre check
flux check --pre
► checking prerequisites
✗ flux 0.25.1 <0.25.2 (new version is available, please upgrade)
✔ Kubernetes 1.21.5-gke.1302 >=1.19.0-0
✔ prerequisites checks passed

# Docker images
docker pull fluxcd/fluxctl:1.24.3
docker pull ghcr.io/fluxcd/flux-cli:1.24.3 # does not work

Cluster bootstrap

FluxCDv2 bootstrap process is installing the Flux onto a cluster and stores(commits) its own manifests to a Git repository.


FLUX_GIT_USERNAME=my-git-username
FLUX_GIT_EMAIL=my-git-email@example.com
flux bootstrap git \
  --author-email=$FLUX_GIT_EMAIL \
  --url=ssh://git@github.com/$FLUX_GIT_USERNAME/gitops-istio \
  --branch=main \
  --path=clusters/my-cluster

At bootstrap, Flux generates an SSH key and prints the public key. In order to sync your cluster state with git you need to copy the public key and create a deploy key with write access on your GitHub repository. On GitHub go to Settings > Deploy keys click on Add deploy key, check Allow write access, paste the Flux public key and click Add key.


Dev installation does not stores its own configuration state in Git repository
# option 1
flux install # install and upgrade
flux install \
--namespace=flux-system \
--network-policy=false \
--components=source-controller

# option 2
kubectl apply -f https://github.com/fluxcd/flux2/releases/latest/download/install.yaml
kustomize build https://github.com/fluxcd/flux2/manifests/install?ref=main | kubectl apply -f- # Upgrade

# Register Git repositories and reconcile them on your cluster:
flux create source git podinfo \
  --url=https://github.com/stefanprodan/podinfo \
  --tag-semver=">=4.0.0" \
  --interval=1m

flux create kustomization podinfo-default \
  --source=podinfo \
  --path="./kustomize" \
  --prune=true \
  --validation=client \
  --interval=10m \
  --health-check="Deployment/podinfo.default" \
  --health-check-timeout=2m

# Register Helm repositories and create Helm releases:
flux create source helm bitnami \
  --interval=1h \
  --url=https://charts.bitnami.com/bitnami

flux create helmrelease nginx \
  --interval=1h \
  --release-name=nginx-ingress-controller \
  --target-namespace=kube-system \
  --source=HelmRepository/bitnami \
  --chart=nginx-ingress-controller \
  --chart-version="5.x.x"


Uninstall

flux uninstall --namespace=flux-system

References


Bundle