# Flux App Delivery Hands-on Tasks - Setup Apps Repository - Create a dedicated GitLab repository for the apps - Onboard the apps repository in the main Flux repository - Flux Kustomization - Add the podinfo deployment manifests to the repository - Create kustomize overlays for configuring podinfo on dev and prod environments - Deploy podinfo from the apps repository on the dev cluster - Run various failure scenarios for the podinfo deployment - Debugging and troubleshooting the podinfo deployment - Flux HelmRelease - Define the podinfo-frontend deployment with OCIRepository and HelmRelease manifests - Setup different values for the dev and prod environments with kustomize overlays - Deploy podinfo-frontend from the apps repository on the dev cluster - Run various scenarios for upgrading, testing and uninstalling - Debugging and troubleshooting the HelmRelease deployment ## Create Apps Repository Create a private GitLab repository named `flux-workshop-apps` and clone it locally: ```shell git clone https://gitlab.com/$GITLAB_USER/flux-workshop-apps.git cd flux-workshop-apps ``` ## Setup podinfo-backend for Flux Kustomization delivery Switch to the `flux-workshop-apps` repository and follow the steps below. ### Create kustomize overlays Create the `podinfo-backend` app structure: ```shell mkdir -p apps/podinfo-backend/base apps/podinfo-backend/dev apps/podinfo-backend/prod ``` Generate the `podinfo-backend` app base structure: ```shell flux pull artifact oci://ghcr.io/stefanprodan/manifests/podinfo:latest \ --output ./apps/podinfo-backend/base/ ``` Create the dev and prod overlays: ```shell tee apps/podinfo-backend/dev/kustomization.yaml apps/podinfo-backend/prod/kustomization.yaml <<'EOF' apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization nameSuffix: -backend resources: - ../base EOF ``` Running `kustomize build` on any overlay should output the same manifests: ```shell kustomize build apps/podinfo-backend/dev kustomize build apps/podinfo-backend/prod ``` Commit the changes to the `flux-workshop-apps` repository: ```shell git add apps git commit -m "Add podinfo-backend" git push origin main ``` ## Onboard podinfo-backend Switch to the `flux-workshop` repository and follow the steps below. To onboard the apps from the `flux-workshop-apps` repository, create a directory named `apps` in the repo root: ```shell mkdir -p apps ``` Create a file `apps/namespace.yaml` that defines the Kubernetes namespace for the apps: ```yaml apiVersion: v1 kind: Namespace metadata: name: apps ``` Create the Flux GitRepository manifests for onboarding the `flux-workshop-apps` repository: ```shell flux -n apps create source git apps \ --url=https://gitlab.com/$GITLAB_USER/flux-workshop-apps.git \ --branch=main \ --secret-ref=apps-git-auth \ --export > apps/source.yaml ``` Create a file `apps/podinfo-backend.yaml` that defines the Flux Kustomization for deploying the app: ```yaml apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: podinfo-backend namespace: apps spec: targetNamespace: apps interval: 10m retryInterval: 5m timeout: 2m wait: true prune: true sourceRef: kind: GitRepository name: apps path: "./apps/podinfo-backend/${CLUSTER_ENV}" commonMetadata: annotations: cluster/name: "${CLUSTER_NAME}" cluster/region: "${CLUSTER_REGION}" ``` Note that the cluster variables are substituted by Flux at runtime from the `cluster-info` ConfigMap. Create `clusters/dev-cluster/apps.yaml` that defines the Flux Kustomization which reconciles the `apps` directory: ```yaml apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: apps namespace: flux-system spec: interval: 10m retryInterval: 5m prune: true sourceRef: kind: GitRepository name: flux-system path: "./apps" postBuild: substituteFrom: - kind: ConfigMap name: cluster-info ``` Commit the changes to the `flux-workshop` repository: ```shell git add -A git commit -m "Onboard apps repository" git push origin main ``` Wait for the `apps` namespace to be created and then create the `apps-git-auth` secret: ```shell flux -n apps create secret git apps-git-auth \ --url=https://gitlab.com/$GITLAB_USER/flux-workshop-apps.git \ --username=flux \ --password=$GITLAB_TOKEN ``` Verify that the `flux-workshop-apps` repository is synced: ```shell flux -n apps get all ``` ## Setup podinfo-frontend for Flux HelmRelease delivery Switch to the `flux-workshop-apps` repository and follow the steps below. ### Create the base overlay for podinfo-frontend Create the `podinfo-frontend` base dir: ```shell mkdir -p apps/podinfo-frontend/base apps/podinfo-frontend/dev apps/podinfo-frontend/prod ``` Create an OCIRepository manifest in `podinfo-frontend/base/source.yaml`: ```yaml apiVersion: source.toolkit.fluxcd.io/v1beta2 kind: OCIRepository metadata: name: podinfo-frontend spec: interval: 10m layerSelector: mediaType: "application/vnd.cncf.helm.chart.content.v1.tar+gzip" operation: copy url: oci://ghcr.io/stefanprodan/charts/podinfo ref: semver: "*" ``` Create a HelmRelease manifest in `podinfo-frontend/base/release.yaml`: ```yaml apiVersion: helm.toolkit.fluxcd.io/v2 kind: HelmRelease metadata: name: podinfo-frontend spec: interval: 10m releaseName: podinfo-frontend driftDetection: mode: enabled chartRef: kind: OCIRepository name: podinfo-frontend valuesFrom: - kind: ConfigMap name: podinfo-values ``` Create a `kustomization.yaml` in `podinfo-frontend/base`: ```yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - source.yaml - release.yaml ``` ### Create the dev and prod overlays for podinfo-frontend Create the `podinfo-frontend` overlays: ```shell mkdir -p apps/podinfo-frontend/dev apps/podinfo-frontend/prod ``` Create a `values.yaml` in `podinfo-frontend/dev`: ```yaml replicaCount: 2 backend: http://podinfo-backend:9898/echo ``` Create a `kustomizeconfig.yaml` in `podinfo-frontend/dev`: ```yaml nameReference: - kind: ConfigMap version: v1 fieldSpecs: - path: spec/valuesFrom/name kind: HelmRelease - kind: Secret version: v1 fieldSpecs: - path: spec/valuesFrom/name kind: HelmRelease ``` Create a `kustomization.yaml` in `podinfo-frontend/dev`: ```yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ../base configMapGenerator: - name: podinfo-values files: - values.yaml=values.yaml configurations: - kustomizeconfig.yaml patches: - patch: | - op: replace path: /spec/ref/semver value: "6.7.0" target: kind: OCIRepository ``` Copy dev overlay to prod: ```shell cp -r apps/podinfo-frontend/dev/. apps/podinfo-frontend/prod ``` Commit the changes to the `flux-workshop-apps` repository: ```shell git add -A git commit -m "Add podinfo-frontend helm release" git push origin main ``` ## Onboard podinfo-frontend Switch to the `flux-workshop` repository and follow the steps below. Create the `podinfo-frontend` Flux Kustomization in `apps/podinfo-frontend.yaml`: ```yaml apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: podinfo-frontend namespace: apps spec: targetNamespace: apps interval: 10m retryInterval: 5m timeout: 5m wait: true prune: true sourceRef: kind: GitRepository name: apps path: "./apps/podinfo-frontend/${CLUSTER_ENV}" commonMetadata: annotations: cluster/name: "${CLUSTER_NAME}" cluster/region: "${CLUSTER_REGION}" ``` Commit the changes to the `flux-workshop` repository: ```shell git add -A git commit -m "Onboard podinfo-frontend" git push origin main ``` Wait for the `podinfo-frontend` HelmRelease to be deployed: ```shell flux get all -A ``` # Flux App Delivery Hands-on Tasks - Setup Apps Repository - Create a dedicated GitLab repository for the apps - Onboard the apps repository in the main Flux repository - Flux Kustomization - Add the podinfo deployment manifests to the repository - Create kustomize overlays for configuring podinfo on dev and prod environments - Deploy podinfo from the apps repository on the dev cluster - Run various failure scenarios for the podinfo deployment - Debugging and troubleshooting the podinfo deployment - Flux HelmRelease - Define the podinfo-frontend deployment with OCIRepository and HelmRelease manifests - Setup different values for the dev and prod environments with kustomize overlays - Deploy podinfo-frontend from the apps repository on the dev cluster - Run various scenarios for upgrading, testing and uninstalling - Debugging and troubleshooting the HelmRelease deployment ## Create Apps Repository Create a private GitLab repository named `flux-workshop-apps` and clone it locally: ```shell git clone https://gitlab.com/$GITLAB_USER/flux-workshop-apps.git cd flux-workshop-apps ``` ## Setup podinfo-backend for Flux Kustomization delivery Switch to the `flux-workshop-apps` repository and follow the steps below. ### Create kustomize overlays Create the `podinfo-backend` app structure: ```shell mkdir -p apps/podinfo-backend/base apps/podinfo-backend/dev apps/podinfo-backend/prod ``` Generate the `podinfo-backend` app base structure: ```shell flux pull artifact oci://ghcr.io/stefanprodan/manifests/podinfo:latest \ --output ./apps/podinfo-backend/base/ ``` Create the dev and prod overlays: ```shell tee apps/podinfo-backend/dev/kustomization.yaml apps/podinfo-backend/prod/kustomization.yaml <<'EOF' apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization nameSuffix: -backend resources: - ../base EOF ``` Running `kustomize build` on any overlay should output the same manifests: ```shell kustomize build apps/podinfo-backend/dev kustomize build apps/podinfo-backend/prod ``` Commit the changes to the `flux-workshop-apps` repository: ```shell git add apps git commit -m "Add podinfo-backend" git push origin main ``` ## Onboard podinfo-backend Switch to the `flux-workshop` repository and follow the steps below. To onboard the apps from the `flux-workshop-apps` repository, create a directory named `apps` in the repo root: ```shell mkdir -p apps ``` Create a file `apps/namespace.yaml` that defines the Kubernetes namespace for the apps: ```yaml apiVersion: v1 kind: Namespace metadata: name: apps ``` Create the Flux GitRepository manifests for onboarding the `flux-workshop-apps` repository: ```shell flux -n apps create source git apps \ --url=https://gitlab.com/$GITLAB_USER/flux-workshop-apps.git \ --branch=main \ --secret-ref=apps-git-auth \ --export > apps/source.yaml ``` Create a file `apps/podinfo-backend.yaml` that defines the Flux Kustomization for deploying the app: ```yaml apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: podinfo-backend namespace: apps spec: targetNamespace: apps interval: 10m retryInterval: 5m timeout: 2m wait: true prune: true sourceRef: kind: GitRepository name: apps path: "./apps/podinfo-backend/${CLUSTER_ENV}" commonMetadata: annotations: cluster/name: "${CLUSTER_NAME}" cluster/region: "${CLUSTER_REGION}" ``` Note that the cluster variables are substituted by Flux at runtime from the `cluster-info` ConfigMap. Create `clusters/dev-cluster/apps.yaml` that defines the Flux Kustomization which reconciles the `apps` directory: ```yaml apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: apps namespace: flux-system spec: interval: 10m retryInterval: 5m prune: true sourceRef: kind: GitRepository name: flux-system path: "./apps" postBuild: substituteFrom: - kind: ConfigMap name: cluster-info ``` Commit the changes to the `flux-workshop` repository: ```shell git add -A git commit -m "Onboard apps repository" git push origin main ``` Wait for the `apps` namespace to be created and then create the `apps-git-auth` secret: ```shell flux -n apps create secret git apps-git-auth \ --url=https://gitlab.com/$GITLAB_USER/flux-workshop-apps.git \ --username=flux \ --password=$GITLAB_TOKEN ``` Verify that the `flux-workshop-apps` repository is synced: ```shell flux -n apps get all ``` ## Setup podinfo-frontend for Flux HelmRelease delivery Switch to the `flux-workshop-apps` repository and follow the steps below. ### Create the base overlay for podinfo-frontend Create the `podinfo-frontend` base dir: ```shell mkdir -p apps/podinfo-frontend/base apps/podinfo-frontend/dev apps/podinfo-frontend/prod ``` Create an OCIRepository manifest in `podinfo-frontend/base/source.yaml`: ```yaml apiVersion: source.toolkit.fluxcd.io/v1beta2 kind: OCIRepository metadata: name: podinfo-frontend spec: interval: 10m layerSelector: mediaType: "application/vnd.cncf.helm.chart.content.v1.tar+gzip" operation: copy url: oci://ghcr.io/stefanprodan/charts/podinfo ref: semver: "*" ``` Create a HelmRelease manifest in `podinfo-frontend/base/release.yaml`: ```yaml apiVersion: helm.toolkit.fluxcd.io/v2 kind: HelmRelease metadata: name: podinfo-frontend spec: interval: 10m releaseName: podinfo-frontend driftDetection: mode: enabled chartRef: kind: OCIRepository name: podinfo-frontend valuesFrom: - kind: ConfigMap name: podinfo-values ``` Create a `kustomization.yaml` in `podinfo-frontend/base`: ```yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - source.yaml - release.yaml ``` ### Create the dev and prod overlays for podinfo-frontend Create the `podinfo-frontend` overlays: ```shell mkdir -p apps/podinfo-frontend/dev apps/podinfo-frontend/prod ``` Create a `values.yaml` in `podinfo-frontend/dev`: ```yaml replicaCount: 2 backend: http://podinfo-backend:9898/echo ``` Create a `kustomizeconfig.yaml` in `podinfo-frontend/dev`: ```yaml nameReference: - kind: ConfigMap version: v1 fieldSpecs: - path: spec/valuesFrom/name kind: HelmRelease - kind: Secret version: v1 fieldSpecs: - path: spec/valuesFrom/name kind: HelmRelease ``` Create a `kustomization.yaml` in `podinfo-frontend/dev`: ```yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ../base configMapGenerator: - name: podinfo-values files: - values.yaml=values.yaml configurations: - kustomizeconfig.yaml patches: - patch: | - op: replace path: /spec/ref/semver value: "6.7.0" target: kind: OCIRepository ``` Copy dev overlay to prod: ```shell cp -r apps/podinfo-frontend/dev/. apps/podinfo-frontend/prod ``` Commit the changes to the `flux-workshop-apps` repository: ```shell git add -A git commit -m "Add podinfo-frontend helm release" git push origin main ``` ## Onboard podinfo-frontend Switch to the `flux-workshop` repository and follow the steps below. Create the `podinfo-frontend` Flux Kustomization in `apps/podinfo-frontend.yaml`: ```yaml apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: podinfo-frontend namespace: apps spec: targetNamespace: apps interval: 10m retryInterval: 5m timeout: 5m wait: true prune: true sourceRef: kind: GitRepository name: apps path: "./apps/podinfo-frontend/${CLUSTER_ENV}" commonMetadata: annotations: cluster/name: "${CLUSTER_NAME}" cluster/region: "${CLUSTER_REGION}" ``` Commit the changes to the `flux-workshop` repository: ```shell git add -A git commit -m "Onboard podinfo-frontend" git push origin main ``` Wait for the `podinfo-frontend` HelmRelease to be deployed: ```shell flux get all -A ```