From dd15b8d7c31c499000514e76a11877f55fb0b36b Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 2 Apr 2024 11:16:44 +0200 Subject: [PATCH 1/9] docs: create use-case for integration with Flux Signed-off-by: odubajDT --- docs/docs/use-cases/assets/flux/app.yaml | 57 ++++++ .../assets/flux/flux-kustomization.yaml | 17 ++ .../use-cases/assets/flux/gitrepository.yaml | 10 + .../docs/use-cases/assets/flux/kustomize.yaml | 4 + docs/docs/use-cases/flux.md | 189 ++++++++++++++++++ mkdocs.yml | 1 + 6 files changed, 278 insertions(+) create mode 100644 docs/docs/use-cases/assets/flux/app.yaml create mode 100644 docs/docs/use-cases/assets/flux/flux-kustomization.yaml create mode 100644 docs/docs/use-cases/assets/flux/gitrepository.yaml create mode 100644 docs/docs/use-cases/assets/flux/kustomize.yaml create mode 100644 docs/docs/use-cases/flux.md diff --git a/docs/docs/use-cases/assets/flux/app.yaml b/docs/docs/use-cases/assets/flux/app.yaml new file mode 100644 index 0000000000..aff9344b49 --- /dev/null +++ b/docs/docs/use-cases/assets/flux/app.yaml @@ -0,0 +1,57 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: podtato-kubectl + annotations: + keptn.sh/lifecycle-toolkit: "enabled" +--- +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnAppContext +metadata: + name: podtato-head +spec: + preDeploymentTasks: + - hello-task +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-entry + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-entry + template: + metadata: + labels: + component: podtato-head-entry + annotations: + keptn.sh/app: podtato-head + keptn.sh/workload: podtato-head-entry + keptn.sh/version: 0.1.0 + keptn.sh/pre-deployment-tasks: hello-task + keptn.sh/post-deployment-tasks: hello-task + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: ghcr.io/podtato-head/entry:latest + imagePullPolicy: Always + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnTaskDefinition +metadata: + name: hello-task +spec: + deno: + inline: + code: | + console.log('hello'); + retries: 3 diff --git a/docs/docs/use-cases/assets/flux/flux-kustomization.yaml b/docs/docs/use-cases/assets/flux/flux-kustomization.yaml new file mode 100644 index 0000000000..a34c4013ea --- /dev/null +++ b/docs/docs/use-cases/assets/flux/flux-kustomization.yaml @@ -0,0 +1,17 @@ +apiVersion: kustomize.toolkit.fluxcd.io/v1 +kind: Kustomization +metadata: + name: app + namespace: flux-system +spec: + interval: 30m0s + path: ./apps/dev + prune: true + retryInterval: 2m0s + sourceRef: + kind: GitRepository + name: app + namespace: flux-system + targetNamespace: podtato-kubectl + timeout: 3m0s + wait: true diff --git a/docs/docs/use-cases/assets/flux/gitrepository.yaml b/docs/docs/use-cases/assets/flux/gitrepository.yaml new file mode 100644 index 0000000000..138e0040b6 --- /dev/null +++ b/docs/docs/use-cases/assets/flux/gitrepository.yaml @@ -0,0 +1,10 @@ +apiVersion: source.toolkit.fluxcd.io/v1 +kind: GitRepository +metadata: + name: app + namespace: flux-system +spec: + interval: 1m0s + ref: + branch: main + url: diff --git a/docs/docs/use-cases/assets/flux/kustomize.yaml b/docs/docs/use-cases/assets/flux/kustomize.yaml new file mode 100644 index 0000000000..30ecf93b91 --- /dev/null +++ b/docs/docs/use-cases/assets/flux/kustomize.yaml @@ -0,0 +1,4 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - app.yaml diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md new file mode 100644 index 0000000000..4df23fd933 --- /dev/null +++ b/docs/docs/use-cases/flux.md @@ -0,0 +1,189 @@ +--- +comments: true +--- + +# Deploying Applications with Flux + +Flux is a tool for keeping Kubernetes clusters in sync with sources +of configuration (like Git repositories), and automating updates to +configuration when there is new code to deploy. + +This section shows an already existing use case of running +[pre and post-deployment jobs with Flux](https://fluxcd.io/flux/use-cases/running-jobs/) +and how Keptn makes it simpler and and more straight-forward. + +## High-level strucutre of the git repository + +Since Flux uses a GitOps approach to continuous delivery, the git +repository structure needs to look like the following: + +``` +├── apps +│ └── dev +│ ├── podtato-head.yaml +│ └── kustomize.yaml +└── clusters + └── dev + ├── flux-system + │ ├── gotk-components.yaml + │ ├── gotk-sync.yaml + │ └── kustomize.yaml + ├── podtato-head-source.yaml + └── podtato-head-kustomization.yaml +``` + +The `apps` directory contains application manifests, that will be deployed. +The `clusters` directory contains Flux configuration manifests and custom +resources, that are needed for the delivery. +`apps` and `clusters` directories can live in two separate repositories, +but for simplicity of this excercise, we will keed them in a single one. + +## Set up environment + +Before starting, you need to install Flux CLI and Keptn. +You can find the installation instructions of Keptn [here](./../installation/index.md) +and for Flux [here](https://fluxcd.io/flux/installation/). + +After succesffully installing Flux CLI and Keptn, you need to +retrieve your git repository credentials. +You can use any available git providers, but be sure to store your `token` +for later usage. +For simplicity, we will use `GitHub`. + +In the end, you need to install Flux to your cluster. +This step will require +[bootstrapping the git repository](https://fluxcd.io/flux/installation/bootstrap/) +in order to set up all Flux structures. +For that, you can use the following command: + +```bash +GITHUB_USER= GITHUB_TOKEN= \ +flux bootstrap github \ + --owner=$GITHUB_USER \ + --repository=podtato-head \ + --branch=main \ + --path=./clusters/dev \ + --personal +``` + +The bootstrap command above does the following: + +* Creates a git repository `podtato-head` on your `GitHub` account. +* Adds Flux component manifests to the repository - +creates `./clusters/dev/flux-system/*` structure. +* Deploys Flux Components to your Kubernetes Cluster. +* Configures Flux components to track the path `./clusters/dev/` in the repository. + +## Creating application + +Now it's time to add the application together with pre- and +post-deployments checks to the repository. + +Firstly, clone the `podtato-head` repository to your local machine. + +Add the following manifests into `podtato-head.yaml` representing the application +and store it into `./apps/dev/` directory of your repository: + +```yaml +{% include "./assets/flux/app.yaml" %} +``` + +Additionally, create a `kustomize.yaml` file right next to it: + +```yaml +{% include "./assets/flux/kustomize.yaml" %} +``` + +You can commit and push these manifests to your git repository. + +> **Note** +Notice, that the application has pre- and post-deployment tasks defined +in the manifests. +This enhances the +[Flux pre and post-deployment jobs](https://fluxcd.io/flux/use-cases/running-jobs/) +setup with added observability out of the box. + +## Set up continuous delivery for the application + +Firstly, we need to create a +[GitRepository](https://fluxcd.io/flux/components/source/gitrepositories/) +Flux custom resource +pointing to a repository where the application manifests are present. +In this case, it will be our `podtato-head` repository. +To create it, we will use Flux CLI: + +```bash +flux create source git podtato-head \ + --url= \ + --branch=main \ + --interval=1m \ + --export > ./clusters/dev/podtato-head-source.yaml +``` + +which will result output similar to: + +```yaml +{% include "./assets/flux/gitrepository.yaml" %} +``` + +In the last step, create a +[Kustomization](https://fluxcd.io/flux/components/kustomize/kustomizations/) +Flux custom resource to deploy the `podtato-head` application to the cluster. +You can create it using the Flux CLI: + +```bash +flux create kustomization podinfo \ + --target-namespace=podtato-kubectl \ + --source=podtato-head \ + --path="./apps/dev" \ + --prune=true \ + --wait=true \ + --interval=30m \ + --retry-interval=2m \ + --health-check-timeout=3m \ + --export > ./clusters/dev/podtato-head-kustomization.yaml +``` + +which will result output similar to: + +```yaml +{% include "./assets/flux/flux-kustomization.yaml" %} +``` + +Now commit and push the resources you created in the recent steps. +After pushing them, Flux should pick up the configuration and +deploy your application into the cluster. + +## Watch Flux sync of the application + +You can watch the synchronization of the application +with Flux CLI + +```bash +$ flux get kustomizations --watch + +NAME REVISION SUSPENDED READY MESSAGE +flux-system main@sha1:4e9c917f False True Applied revision: main@sha1:4e9c917f +podtato-head main@sha1:44157ecd False True Applied revision: main@sha1:44157ecd + +``` + +or using `kubectl`: + +```shell +$ kubectl get keptnappversion -n podtato-head + +NAME APPNAME VERSION PHASE +podtato-head-v0.1.0-6b86b273 podtato-head v0.1.0 Completed +``` + +Every time you update the application, the changes will be +synced to the cluster. + +## Possible follow-ups + +You can set up a multi-stage delivery with Flux, same +as it was done with `ArgoCD`. +You can follow similar steps to the +[ArgoCD multi-stage delivery with Keptn](../guides/multi-stage-application-delivery.md) +user guide. diff --git a/mkdocs.yml b/mkdocs.yml index cfdce55cd9..cdfe00c77a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -149,6 +149,7 @@ nav: - Day 2 Operations: docs/use-cases/day-2-operations.md - Keptn + HorizontalPodAutoscaler: docs/use-cases/hpa.md - Keptn + KEDA: docs/use-cases/keda.md + - Keptn + Flux: docs/use-cases/flux.md - Keptn for non-Kubernetes deployments: docs/use-cases/non-k8s.md - Components: - docs/components/index.md From becc433138fb3833de3c227cf0020ae78359879e Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 2 Apr 2024 11:23:04 +0200 Subject: [PATCH 2/9] fix checks Signed-off-by: odubajDT --- .github/actions/spelling/expect.txt | 3 +++ docs/docs/use-cases/flux.md | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 4a5f3dd6a4..c6b55f5272 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -185,6 +185,7 @@ fieldpath fieldref finalizer flyout +fluxcd fontawesome ftp fullname @@ -207,6 +208,7 @@ ginkgotypes giscus Gitlab gitops +gitrepository gke glasskube gms @@ -223,6 +225,7 @@ goodanalysis goodmetric goodtaskdefinition google +gotk govulncheck Grabner grafana diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md index 4df23fd933..b2117d6d50 100644 --- a/docs/docs/use-cases/flux.md +++ b/docs/docs/use-cases/flux.md @@ -12,12 +12,12 @@ This section shows an already existing use case of running [pre and post-deployment jobs with Flux](https://fluxcd.io/flux/use-cases/running-jobs/) and how Keptn makes it simpler and and more straight-forward. -## High-level strucutre of the git repository +## High-level structure of the git repository Since Flux uses a GitOps approach to continuous delivery, the git repository structure needs to look like the following: -``` +```markdown ├── apps │ └── dev │ ├── podtato-head.yaml @@ -36,7 +36,7 @@ The `apps` directory contains application manifests, that will be deployed. The `clusters` directory contains Flux configuration manifests and custom resources, that are needed for the delivery. `apps` and `clusters` directories can live in two separate repositories, -but for simplicity of this excercise, we will keed them in a single one. +but for simplicity of this excercise, we will keep them in a single one. ## Set up environment @@ -44,7 +44,7 @@ Before starting, you need to install Flux CLI and Keptn. You can find the installation instructions of Keptn [here](./../installation/index.md) and for Flux [here](https://fluxcd.io/flux/installation/). -After succesffully installing Flux CLI and Keptn, you need to +After successfully installing Flux CLI and Keptn, you need to retrieve your git repository credentials. You can use any available git providers, but be sure to store your `token` for later usage. @@ -105,7 +105,7 @@ setup with added observability out of the box. ## Set up continuous delivery for the application -Firstly, we need to create a +Firstly, we need to create a [GitRepository](https://fluxcd.io/flux/components/source/gitrepositories/) Flux custom resource pointing to a repository where the application manifests are present. @@ -132,7 +132,7 @@ Flux custom resource to deploy the `podtato-head` application to the cluster. You can create it using the Flux CLI: ```bash -flux create kustomization podinfo \ +flux create kustomization podtato-head \ --target-namespace=podtato-kubectl \ --source=podtato-head \ --path="./apps/dev" \ @@ -164,7 +164,7 @@ $ flux get kustomizations --watch NAME REVISION SUSPENDED READY MESSAGE flux-system main@sha1:4e9c917f False True Applied revision: main@sha1:4e9c917f -podtato-head main@sha1:44157ecd False True Applied revision: main@sha1:44157ecd +podtato-head main@sha1:44154333 False True Applied revision: main@sha1:44154333 ``` From 411fb5512b3d439ba76b6860107051da639031e5 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 2 Apr 2024 13:03:19 +0200 Subject: [PATCH 3/9] polish Signed-off-by: odubajDT --- docs/docs/use-cases/flux.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md index b2117d6d50..116908c3ec 100644 --- a/docs/docs/use-cases/flux.md +++ b/docs/docs/use-cases/flux.md @@ -8,14 +8,14 @@ Flux is a tool for keeping Kubernetes clusters in sync with sources of configuration (like Git repositories), and automating updates to configuration when there is new code to deploy. -This section shows an already existing use case of running +This section shows an already existing Flux use case of running [pre and post-deployment jobs with Flux](https://fluxcd.io/flux/use-cases/running-jobs/) and how Keptn makes it simpler and and more straight-forward. ## High-level structure of the git repository -Since Flux uses a GitOps approach to continuous delivery, the git -repository structure needs to look like the following: +Since Flux uses a GitOps approach for continuous delivery, the git +repository structure, for our use case, will look like the following: ```markdown ├── apps @@ -40,7 +40,7 @@ but for simplicity of this excercise, we will keep them in a single one. ## Set up environment -Before starting, you need to install Flux CLI and Keptn. +Before we start, you need to install Flux CLI and Keptn. You can find the installation instructions of Keptn [here](./../installation/index.md) and for Flux [here](https://fluxcd.io/flux/installation/). @@ -50,10 +50,10 @@ You can use any available git providers, but be sure to store your `token` for later usage. For simplicity, we will use `GitHub`. -In the end, you need to install Flux to your cluster. +As another step, you need to install Flux to your cluster. This step will require [bootstrapping the git repository](https://fluxcd.io/flux/installation/bootstrap/) -in order to set up all Flux structures. +in order to set up all needed Flux structures in the repository. For that, you can use the following command: ```bash @@ -94,7 +94,7 @@ Additionally, create a `kustomize.yaml` file right next to it: {% include "./assets/flux/kustomize.yaml" %} ``` -You can commit and push these manifests to your git repository. +You can commit and push these manifests to the git repository. > **Note** Notice, that the application has pre- and post-deployment tasks defined @@ -120,7 +120,7 @@ flux create source git podtato-head \ --export > ./clusters/dev/podtato-head-source.yaml ``` -which will result output similar to: +which results in an output similar to: ```yaml {% include "./assets/flux/gitrepository.yaml" %} @@ -144,15 +144,15 @@ flux create kustomization podtato-head \ --export > ./clusters/dev/podtato-head-kustomization.yaml ``` -which will result output similar to: +which results in an output similar to: ```yaml {% include "./assets/flux/flux-kustomization.yaml" %} ``` Now commit and push the resources you created in the recent steps. -After pushing them, Flux should pick up the configuration and -deploy your application into the cluster. +After pushing them, Flux picks up the configuration and +deploys your application into the cluster. ## Watch Flux sync of the application @@ -182,8 +182,8 @@ synced to the cluster. ## Possible follow-ups -You can set up a multi-stage delivery with Flux, same +You can also set up a multi-stage delivery with Flux, same as it was done with `ArgoCD`. -You can follow similar steps to the +You can follow the steps of the [ArgoCD multi-stage delivery with Keptn](../guides/multi-stage-application-delivery.md) user guide. From 7c6552f43c530d6a59504e71cc323b09c39aee0c Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Wed, 3 Apr 2024 07:29:04 +0200 Subject: [PATCH 4/9] Apply suggestions from code review Co-authored-by: Meg McRoberts Signed-off-by: odubajDT <93584209+odubajDT@users.noreply.github.com> --- docs/docs/use-cases/flux.md | 61 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md index 116908c3ec..3cb838027d 100644 --- a/docs/docs/use-cases/flux.md +++ b/docs/docs/use-cases/flux.md @@ -2,20 +2,20 @@ comments: true --- -# Deploying Applications with Flux +# Deploying Applications with Flux and Keptn -Flux is a tool for keeping Kubernetes clusters in sync with sources -of configuration (like Git repositories), and automating updates to -configuration when there is new code to deploy. +Flux is a tool that keeps Kubernetes clusters synchronized with sources +of configuration (such as Git repositories) and automate updates to +configuration when new code is deployed. -This section shows an already existing Flux use case of running +This section shows how to add Keptn to an existing Flux use case that runs [pre and post-deployment jobs with Flux](https://fluxcd.io/flux/use-cases/running-jobs/) -and how Keptn makes it simpler and and more straight-forward. +to make it simpler and and more straight-forward. ## High-level structure of the git repository Since Flux uses a GitOps approach for continuous delivery, the git -repository structure, for our use case, will look like the following: +repository structure for our use case looks like the following: ```markdown ├── apps @@ -41,20 +41,20 @@ but for simplicity of this excercise, we will keep them in a single one. ## Set up environment Before we start, you need to install Flux CLI and Keptn. -You can find the installation instructions of Keptn [here](./../installation/index.md) +You can find the installation instructions for Keptn [here](./../installation/index.md) and for Flux [here](https://fluxcd.io/flux/installation/). After successfully installing Flux CLI and Keptn, you need to -retrieve your git repository credentials. -You can use any available git providers, but be sure to store your `token` +retrieve your Git repository credentials. +You can use any available Git providers, but be sure to store your `token` for later usage. For simplicity, we will use `GitHub`. -As another step, you need to install Flux to your cluster. -This step will require +You also need to install Flux in your cluster. +This requires [bootstrapping the git repository](https://fluxcd.io/flux/installation/bootstrap/) -in order to set up all needed Flux structures in the repository. -For that, you can use the following command: +to set up all necessary Flux structures in the repository. +Use the following command to do this: ```bash GITHUB_USER= GITHUB_TOKEN= \ @@ -71,7 +71,7 @@ The bootstrap command above does the following: * Creates a git repository `podtato-head` on your `GitHub` account. * Adds Flux component manifests to the repository - creates `./clusters/dev/flux-system/*` structure. -* Deploys Flux Components to your Kubernetes Cluster. +* Deploys Flux components to your Kubernetes Cluster. * Configures Flux components to track the path `./clusters/dev/` in the repository. ## Creating application @@ -81,8 +81,8 @@ post-deployments checks to the repository. Firstly, clone the `podtato-head` repository to your local machine. -Add the following manifests into `podtato-head.yaml` representing the application -and store it into `./apps/dev/` directory of your repository: +Add the following manifests that represent the application into the `podtato-head.yaml` file +and store it in the `./apps/dev/` directory of your repository: ```yaml {% include "./assets/flux/app.yaml" %} @@ -94,10 +94,10 @@ Additionally, create a `kustomize.yaml` file right next to it: {% include "./assets/flux/kustomize.yaml" %} ``` -You can commit and push these manifests to the git repository. +You can commit and push these manifests to the Git repository. > **Note** -Notice, that the application has pre- and post-deployment tasks defined +The application has Keptn pre- and post-deployment tasks defined in the manifests. This enhances the [Flux pre and post-deployment jobs](https://fluxcd.io/flux/use-cases/running-jobs/) @@ -105,12 +105,12 @@ setup with added observability out of the box. ## Set up continuous delivery for the application -Firstly, we need to create a +Firstly, we need to create a Flux [GitRepository](https://fluxcd.io/flux/components/source/gitrepositories/) -Flux custom resource +resource pointing to a repository where the application manifests are present. In this case, it will be our `podtato-head` repository. -To create it, we will use Flux CLI: +To create this resource, we use Flux CLI: ```bash flux create source git podtato-head \ @@ -120,15 +120,15 @@ flux create source git podtato-head \ --export > ./clusters/dev/podtato-head-source.yaml ``` -which results in an output similar to: +which results in output similar to: ```yaml {% include "./assets/flux/gitrepository.yaml" %} ``` -In the last step, create a +In the last step, create a Flux [Kustomization](https://fluxcd.io/flux/components/kustomize/kustomizations/) -Flux custom resource to deploy the `podtato-head` application to the cluster. +resource to deploy the `podtato-head` application to the cluster. You can create it using the Flux CLI: ```bash @@ -144,7 +144,7 @@ flux create kustomization podtato-head \ --export > ./clusters/dev/podtato-head-kustomization.yaml ``` -which results in an output similar to: +which results in output similar to: ```yaml {% include "./assets/flux/flux-kustomization.yaml" %} @@ -157,7 +157,7 @@ deploys your application into the cluster. ## Watch Flux sync of the application You can watch the synchronization of the application -with Flux CLI +using the Flux CLI: ```bash $ flux get kustomizations --watch @@ -177,13 +177,12 @@ NAME APPNAME VERSION PHASE podtato-head-v0.1.0-6b86b273 podtato-head v0.1.0 Completed ``` -Every time you update the application, the changes will be +Each time you update the application, the changes are synced to the cluster. ## Possible follow-ups -You can also set up a multi-stage delivery with Flux, same -as it was done with `ArgoCD`. -You can follow the steps of the +You can also set up a multi-stage delivery with Flux, +following the steps described for `ArgoCD` in the [ArgoCD multi-stage delivery with Keptn](../guides/multi-stage-application-delivery.md) user guide. From 29f50ef64b597e4672747077c3fcb3dd803094d8 Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Wed, 3 Apr 2024 13:40:08 +0200 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Moritz Wiesinger Signed-off-by: odubajDT <93584209+odubajDT@users.noreply.github.com> --- docs/docs/use-cases/flux.md | 38 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md index 3cb838027d..4ce513b5f3 100644 --- a/docs/docs/use-cases/flux.md +++ b/docs/docs/use-cases/flux.md @@ -5,16 +5,16 @@ comments: true # Deploying Applications with Flux and Keptn Flux is a tool that keeps Kubernetes clusters synchronized with sources -of configuration (such as Git repositories) and automate updates to +of configuration (such as Git repositories) and automates updates to configuration when new code is deployed. This section shows how to add Keptn to an existing Flux use case that runs [pre and post-deployment jobs with Flux](https://fluxcd.io/flux/use-cases/running-jobs/) -to make it simpler and and more straight-forward. +to make it simpler and more straight-forward. -## High-level structure of the git repository +## High-level structure of the Git repository -Since Flux uses a GitOps approach for continuous delivery, the git +Since Flux uses a GitOps approach for continuous delivery, the Git repository structure for our use case looks like the following: ```markdown @@ -38,17 +38,17 @@ resources, that are needed for the delivery. `apps` and `clusters` directories can live in two separate repositories, but for simplicity of this excercise, we will keep them in a single one. -## Set up environment +## Set up your environment Before we start, you need to install Flux CLI and Keptn. -You can find the installation instructions for Keptn [here](./../installation/index.md) +You can find the installation instructions for Keptn [here](../installation/index.md) and for Flux [here](https://fluxcd.io/flux/installation/). After successfully installing Flux CLI and Keptn, you need to retrieve your Git repository credentials. You can use any available Git providers, but be sure to store your `token` for later usage. -For simplicity, we will use `GitHub`. +For simplicity, we will use GitHub. You also need to install Flux in your cluster. This requires @@ -56,7 +56,7 @@ This requires to set up all necessary Flux structures in the repository. Use the following command to do this: -```bash +```shell GITHUB_USER= GITHUB_TOKEN= \ flux bootstrap github \ --owner=$GITHUB_USER \ @@ -68,18 +68,18 @@ flux bootstrap github \ The bootstrap command above does the following: -* Creates a git repository `podtato-head` on your `GitHub` account. +* Creates a Git repository `podtato-head` on your GitHub account. * Adds Flux component manifests to the repository - creates `./clusters/dev/flux-system/*` structure. * Deploys Flux components to your Kubernetes Cluster. * Configures Flux components to track the path `./clusters/dev/` in the repository. -## Creating application +## Creating the application Now it's time to add the application together with pre- and -post-deployments checks to the repository. +post-deployment checks to the repository. -Firstly, clone the `podtato-head` repository to your local machine. +First, clone the `podtato-head` repository to your local machine. Add the following manifests that represent the application into the `podtato-head.yaml` file and store it in the `./apps/dev/` directory of your repository: @@ -96,7 +96,6 @@ Additionally, create a `kustomize.yaml` file right next to it: You can commit and push these manifests to the Git repository. -> **Note** The application has Keptn pre- and post-deployment tasks defined in the manifests. This enhances the @@ -105,14 +104,14 @@ setup with added observability out of the box. ## Set up continuous delivery for the application -Firstly, we need to create a Flux +First, we need to create a Flux [GitRepository](https://fluxcd.io/flux/components/source/gitrepositories/) resource pointing to a repository where the application manifests are present. In this case, it will be our `podtato-head` repository. To create this resource, we use Flux CLI: -```bash +```shell flux create source git podtato-head \ --url= \ --branch=main \ @@ -131,7 +130,7 @@ In the last step, create a Flux resource to deploy the `podtato-head` application to the cluster. You can create it using the Flux CLI: -```bash +```shell flux create kustomization podtato-head \ --target-namespace=podtato-kubectl \ --source=podtato-head \ @@ -150,7 +149,7 @@ which results in output similar to: {% include "./assets/flux/flux-kustomization.yaml" %} ``` -Now commit and push the resources you created in the recent steps. +Now, commit and push the resources you created in the recent steps. After pushing them, Flux picks up the configuration and deploys your application into the cluster. @@ -159,13 +158,12 @@ deploys your application into the cluster. You can watch the synchronization of the application using the Flux CLI: -```bash +```shell $ flux get kustomizations --watch NAME REVISION SUSPENDED READY MESSAGE flux-system main@sha1:4e9c917f False True Applied revision: main@sha1:4e9c917f podtato-head main@sha1:44154333 False True Applied revision: main@sha1:44154333 - ``` or using `kubectl`: @@ -182,7 +180,7 @@ synced to the cluster. ## Possible follow-ups -You can also set up a multi-stage delivery with Flux, +You can also set up multi-stage delivery with Flux, following the steps described for `ArgoCD` in the [ArgoCD multi-stage delivery with Keptn](../guides/multi-stage-application-delivery.md) user guide. From 660e8d4078bb918d0f6a6f50edab37b81423e989 Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Fri, 5 Apr 2024 06:59:44 +0200 Subject: [PATCH 6/9] Apply suggestions from code review Co-authored-by: Meg McRoberts Signed-off-by: odubajDT <93584209+odubajDT@users.noreply.github.com> --- docs/docs/use-cases/flux.md | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md index 4ce513b5f3..43593f8555 100644 --- a/docs/docs/use-cases/flux.md +++ b/docs/docs/use-cases/flux.md @@ -4,17 +4,23 @@ comments: true # Deploying Applications with Flux and Keptn -Flux is a tool that keeps Kubernetes clusters synchronized with sources +[Flux](https://fluxcd.io/) +is a tool that keeps Kubernetes clusters synchronized with sources of configuration (such as Git repositories) and automates updates to -configuration when new code is deployed. +the configuration when new code is deployed. -This section shows how to add Keptn to an existing Flux use case that runs -[pre and post-deployment jobs with Flux](https://fluxcd.io/flux/use-cases/running-jobs/) -to make it simpler and more straight-forward. +This section shows how to add Keptn +[pre- and post-deploymnt tasks](../guides/tasks.md) +to an existing Flux use case that runs +[pre and post-deployment jobs with Flux](https://fluxcd.io/flux/use-cases/running-jobs/). +Adding Keptn makes it simpler and more straight-forward +to run the Flux pre and post-deployment jobs +and provides added observability out of the box. ## High-level structure of the Git repository -Since Flux uses a GitOps approach for continuous delivery, the Git +Flux uses a GitOps approach for continuous delivery. +The Git repository structure for our use case looks like the following: ```markdown @@ -35,7 +41,7 @@ repository structure for our use case looks like the following: The `apps` directory contains application manifests, that will be deployed. The `clusters` directory contains Flux configuration manifests and custom resources, that are needed for the delivery. -`apps` and `clusters` directories can live in two separate repositories, +The `apps` and `clusters` directories can live in two separate repositories, but for simplicity of this excercise, we will keep them in a single one. ## Set up your environment @@ -52,7 +58,7 @@ For simplicity, we will use GitHub. You also need to install Flux in your cluster. This requires -[bootstrapping the git repository](https://fluxcd.io/flux/installation/bootstrap/) +[bootstrapping the Git repository](https://fluxcd.io/flux/installation/bootstrap/) to set up all necessary Flux structures in the repository. Use the following command to do this: @@ -69,14 +75,14 @@ flux bootstrap github \ The bootstrap command above does the following: * Creates a Git repository `podtato-head` on your GitHub account. -* Adds Flux component manifests to the repository - +* Adds Flux component manifests to the repository and creates `./clusters/dev/flux-system/*` structure. * Deploys Flux components to your Kubernetes Cluster. * Configures Flux components to track the path `./clusters/dev/` in the repository. ## Creating the application -Now it's time to add the application together with pre- and +Now it's time to add the Keptn application that defines the Keptn pre- and post-deployment checks to the repository. First, clone the `podtato-head` repository to your local machine. @@ -119,7 +125,7 @@ flux create source git podtato-head \ --export > ./clusters/dev/podtato-head-source.yaml ``` -which results in output similar to: +This results in output similar to: ```yaml {% include "./assets/flux/gitrepository.yaml" %} @@ -149,7 +155,7 @@ which results in output similar to: {% include "./assets/flux/flux-kustomization.yaml" %} ``` -Now, commit and push the resources you created in the recent steps. +Now, commit and push the resources you created in the previous steps. After pushing them, Flux picks up the configuration and deploys your application into the cluster. From fc572ceacafd2ea01c9fdab05efe69d6d681705f Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Fri, 5 Apr 2024 07:01:58 +0200 Subject: [PATCH 7/9] Update docs/docs/use-cases/flux.md Signed-off-by: odubajDT <93584209+odubajDT@users.noreply.github.com> --- docs/docs/use-cases/flux.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md index 43593f8555..f4755eeb35 100644 --- a/docs/docs/use-cases/flux.md +++ b/docs/docs/use-cases/flux.md @@ -10,7 +10,7 @@ of configuration (such as Git repositories) and automates updates to the configuration when new code is deployed. This section shows how to add Keptn -[pre- and post-deploymnt tasks](../guides/tasks.md) +[pre- and post-deployment tasks](../guides/tasks.md) to an existing Flux use case that runs [pre and post-deployment jobs with Flux](https://fluxcd.io/flux/use-cases/running-jobs/). Adding Keptn makes it simpler and more straight-forward From c1705c1954000b6440274add9641d4b31294895a Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Fri, 5 Apr 2024 08:57:38 +0200 Subject: [PATCH 8/9] Update docs/docs/use-cases/flux.md Co-authored-by: Meg McRoberts Signed-off-by: odubajDT <93584209+odubajDT@users.noreply.github.com> --- docs/docs/use-cases/flux.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md index f4755eeb35..7a1826bfd4 100644 --- a/docs/docs/use-cases/flux.md +++ b/docs/docs/use-cases/flux.md @@ -44,6 +44,11 @@ resources, that are needed for the delivery. The `apps` and `clusters` directories can live in two separate repositories, but for simplicity of this excercise, we will keep them in a single one. +You see that the Keptn runs pre/post-deployment tasks +rather than using the Flux `pre-deploy` and `post-deploy` directories in the Git repository. +The Keptn process is easier to implement +and contains more information than the Flux jobs do. + ## Set up your environment Before we start, you need to install Flux CLI and Keptn. From 82795da18b1dca78f8f8b1946e43f28f6d87c752 Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Fri, 5 Apr 2024 10:16:57 +0200 Subject: [PATCH 9/9] Apply suggestions from code review Co-authored-by: Meg McRoberts Signed-off-by: odubajDT <93584209+odubajDT@users.noreply.github.com> --- docs/docs/use-cases/flux.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/docs/use-cases/flux.md b/docs/docs/use-cases/flux.md index 7a1826bfd4..319182f9ba 100644 --- a/docs/docs/use-cases/flux.md +++ b/docs/docs/use-cases/flux.md @@ -51,7 +51,7 @@ and contains more information than the Flux jobs do. ## Set up your environment -Before we start, you need to install Flux CLI and Keptn. +Before we start, you need to install Flux CLI on your local machine and Keptn on your cluster. You can find the installation instructions for Keptn [here](../installation/index.md) and for Flux [here](https://fluxcd.io/flux/installation/). @@ -61,10 +61,11 @@ You can use any available Git providers, but be sure to store your `token` for later usage. For simplicity, we will use GitHub. -You also need to install Flux in your cluster. -This requires -[bootstrapping the Git repository](https://fluxcd.io/flux/installation/bootstrap/) -to set up all necessary Flux structures in the repository. +You then need to +[bootstrap the Git repository](https://fluxcd.io/flux/installation/bootstrap/), +supplying the `token` you saved, +to install Flux in your cluster. +This sets up all necessary Flux structures in the repository. Use the following command to do this: ```shell @@ -99,6 +100,12 @@ and store it in the `./apps/dev/` directory of your repository: {% include "./assets/flux/app.yaml" %} ``` +See the Keptn +[CRD reference](../reference/crd-reference/index.md) +documentation for more information about the Keptn resources that are used. +See +[Basic annotations](../guides/integrate.md#basic-annotations) +for a description of the labels and annotations that Keptn uses. Additionally, create a `kustomize.yaml` file right next to it: ```yaml