From 49d584bba9f114268a805230a35f0e29f8214ef4 Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Wed, 10 Apr 2024 17:43:38 +0300 Subject: [PATCH] Add workload customization to docs Signed-off-by: Stefan Prodan --- README.md | 60 +++++++++++++++++++ clusters/production/apps/podinfo-values.yaml | 2 +- .../ingress-nginx-values.yaml | 8 +++ .../infra-controllers/kustomization.yaml | 5 ++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 clusters/production/infra-controllers/ingress-nginx-values.yaml diff --git a/README.md b/README.md index bc8dd95..de40767 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # flux2-hub-spoke-example +[![test](https://github.com/fluxcd/flux2-hub-spoke-example/workflows/test/badge.svg)](https://github.com/fluxcd/flux2-hub-spoke-example/actions) +[![e2e](https://github.com/fluxcd/flux2-hub-spoke-example/workflows/e2e/badge.svg)](https://github.com/fluxcd/flux2-hub-spoke-example/actions) +[![license](https://img.shields.io/github/license/fluxcd/flux2-hub-spoke-example.svg)](https://github.com/fluxcd/flux2-hub-spoke-example/blob/main/LICENSE) + This repository showcases how to run Flux on a central Kubernetes cluster and have it manage the GitOps continuous delivery of apps and infrastructure workloads on multiple clusters. @@ -127,6 +131,62 @@ ingress-nginx ingress-nginx-controller-55474d95c5-mq8mj 1/1 podinfo podinfo-66f4ccb98c-bt99t 1/1 ``` +## Customize the workloads + +Assuming you want to ship workloads to the production cluster with a different configuration, +you can employ Kustomize patches in the `clusters/production` overlay and change the Flux HelmRelease values. + +For example, to change the number of replicas for `ingress-nginx` in the production cluster, +you can create a patch file in `clusters/production/infra-controllers/ingress-nginx-values.yaml`: + +```yaml +apiVersion: helm.toolkit.fluxcd.io/v2beta2 +kind: HelmRelease +metadata: + name: ingress-nginx +spec: + values: + controller: + replicaCount: 2 +``` + +And then apply the patch to the `ingress-nginx` HelmRelease in the +`clusters/production/infra-controllers/kustomization.yaml` file with: + +```yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ../../../deploy/infra-controllers +patches: + - target: + kind: HelmRelease + name: ingress-nginx + path: ingress-nginx-values.yaml +``` + +Verify that the patch is correctly applied with: + +```shell +kustomize build ./clusters/production/infra-controllers/ +``` + +After you commit the changes to the repository, Flux will automatically apply the changes. + +You can trigger a manual reconciliation with: + +```shell +flux -n production reconcile ks infra-controllers --with-source +``` + +To verify the number of pods, you can list the deployments in the production cluster: + +```console +kubectl --context kind-flux-production -n ingress-nginx get deploy +NAME READY UP-TO-DATE +ingress-nginx-controller 2/2 2 +``` + ## Testing After making changes to the manifests, you can validate them locally with [kubeconform](https://github.com/yannh/kubeconform) by running: diff --git a/clusters/production/apps/podinfo-values.yaml b/clusters/production/apps/podinfo-values.yaml index bf56292..51a28d9 100644 --- a/clusters/production/apps/podinfo-values.yaml +++ b/clusters/production/apps/podinfo-values.yaml @@ -5,7 +5,7 @@ metadata: spec: chart: spec: - version: ">=1.0.0-alpha" + version: ">=1.0.0" test: enable: false values: diff --git a/clusters/production/infra-controllers/ingress-nginx-values.yaml b/clusters/production/infra-controllers/ingress-nginx-values.yaml new file mode 100644 index 0000000..5ae692f --- /dev/null +++ b/clusters/production/infra-controllers/ingress-nginx-values.yaml @@ -0,0 +1,8 @@ +apiVersion: helm.toolkit.fluxcd.io/v2beta2 +kind: HelmRelease +metadata: + name: ingress-nginx +spec: + values: + controller: + replicaCount: 2 diff --git a/clusters/production/infra-controllers/kustomization.yaml b/clusters/production/infra-controllers/kustomization.yaml index cb95b5d..ad77482 100644 --- a/clusters/production/infra-controllers/kustomization.yaml +++ b/clusters/production/infra-controllers/kustomization.yaml @@ -2,3 +2,8 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ../../../deploy/infra-controllers +patches: + - target: + kind: HelmRelease + name: ingress-nginx + path: ingress-nginx-values.yaml