In the project “https://github.com/fluxcd/flux2-kustomize-helm-example/”, the repository structure and Kustomize patches help reduce code duplication and improve maintainability by using Kustomize for configuration management and Helm for deploying applications.
Kustomize is a standalone tool to customize Kubernetes objects through a kustomization file. It allows for reusing and overlaying base configurations, minimizing duplication. The repository structure in “https://github.com/fluxcd/flux2-kustomize-helm-example/” demonstrates this approach with the following directory structure:
flux2-kustomize-helm-example/
├── clusters/
│ └── dev/
│ └── flux-system/
│ ├── gotk-components.yaml
│ ├── gotk-sync.yaml
│ └── kustomization.yaml
└── overlays/
└── dev/
├── kustomization.yaml
├── kustomize-controller.yaml
├── helm-controller.yaml
├── notification-controller.yaml
└── source-controller.yaml
The kustomization.yaml
files in the overlays/dev/
directory use Kustomize patches to customize the base configurations in clusters/dev/flux-system/
. For example, the source-controller.yaml
in the overlays/dev/
directory contains patches to customize the source-controller
Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: source-controller
patchesStrategicMerge:
- patch: |
- op: add
path: /spec/template/spec/containers/0/args/-
value: --helm-cache-max-size=10
- op: add
path: /spec/template/spec/containers/0/args/-
value: --helm-cache-ttl=60m
- op: add
path: /spec/template/spec/containers/0/args/-
value: --helm-cache-purge-interval=5m
This approach allows for reusing the base configurations and customizing them for specific environments (in this case, dev
), minimizing duplication and improving maintainability.
Additionally, the project uses Helm for deploying applications, which also helps reduce duplication. Helm Charts are reusable packages that can be shared and used across different projects and environments. The Chart.yaml
file in a Helm Chart defines the chart’s metadata, and the values.yaml
file contains default configuration values that can be overridden during installation. This separation of concerns allows for easy customization and reuse of Helm Charts.
In the project “https://github.com/fluxcd/flux2-kustomize-helm-example/”, the Chart.yaml
and values.yaml
files for the PodInfo application are located in the charts/podinfo/
directory. The Kustomization file in overlays/dev/
references the PodInfo Helm Chart and provides custom values for the dev
environment:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../charts/podinfo
helmCharts:
- chart: podinfo
values:
- values.yaml
- overlay-values.yaml
The overlay-values.yaml
file in overlays/dev/
contains custom values for the dev
environment:
image:
tag: v2.22.0
replicaCount: 3
service:
type: ClusterIP
port: 80
targetPort: 9898
By using Kustomize and Helm together, the project “https://github.com/fluxcd/flux2-kustomize-helm-example/” demonstrates best practices for minimizing duplication and improving maintainability in a GitOps environment.
Sources:
- Flux vertical scaling: https://fluxcd.io/flux/installation/configuration/vertical-scaling
- GitOps for Helm Users · GitHub: https://gist.github.com/scottrigby/a1a42c3292ec7899837c578ffdaaf92a
- Security Best Practices | Flux: https://fluxcd.io/flux/security/best-practices
- December Update | Flux: https://fluxcd.io/blog/2020/12/december-update
- Use Flux to support Helm chart propagation | karmada: https://karmada.io/docs/next/userguide/cicd/working-with-flux
- Frequently asked questions | Flux: https://fluxcd.io/flux/faq
- Get Started with Flux | Flux: https://fluxcd.io/flux/get-started
- flux resume source chart | Flux: https://fluxcd.io/flux/cmd/flux_resume_source_chart
- Flux Roadmap | Flux: https://fluxcd.io/roadmap
- flux reconcile helmrelease | Flux: https://fluxcd.io/flux/cmd/flux_reconcile_helmrelease