Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ricsanfre/fluxcd-test
https://github.com/ricsanfre/fluxcd-test
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/ricsanfre/fluxcd-test
- Owner: ricsanfre
- Created: 2024-07-25T06:35:19.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-07-31T14:06:25.000Z (3 months ago)
- Last Synced: 2024-07-31T18:52:19.907Z (3 months ago)
- Language: Makefile
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flux
## Flux cli installation
```shell
curl -s https://fluxcd.io/install.sh | sudo bash
```## Flux Bootstrap
```shell
flux bootstrap github \
--token-auth \
--owner=ricsanfre \
--repository=fluxcd-test \
--branch=master \
--path=kubernetes/clusters/dev \
--personal
```The GitHub PAT will be requested when executing this command.
### PAT secret
Note that the GitHub PAT is stored in the cluster as a Kubernetes Secret named flux-system inside the flux-system namespace.The following secret is automatic created by flux bootstrap command
```yaml
apiVersion: v1
data:
password:
username:
kind: Secret
metadata:
name: flux-system
namespace: flux-system
type: Opaque```
## Flux CD design patterns### Flux HelmChart configuration with overlays
- Provide values.yaml files from configMaps, using Kustomize's configMap generator.
- Base and Overlay values.yaml file
- Config Maps are suffixed with a hashe code over its content.
- if configMap content is changed, name is also changed forcing the re-deploy of all resources using that configMap.Sample code of this design pattern here: https://github.com/moonswitch-workshops/terraform-eks-flux
## Kustomize and Flux advanced options
### Kustomize Components
https://github.com/kubernetes-sigs/kustomize/blob/master/examples/components.md
### Flux Kustomization Templating
Flux Kustomize provides [Post Build Variable Substitution](https://fluxcd.io/flux/components/kustomize/kustomizations/#post-build-variable-substitution) enabling the use of Flux manifest templates
In any resource defined in the Kustomization, a set of variables can be defined. Flux replace these values ither from static values or from ConfigMaps and Secrets after `kustomize build` command is executed.
Sample:
```yaml
apiVersion: v1
kind: Namespace
metadata:
name: apps
labels:
environment: ${cluster_env:=dev}
region: "${cluster_region}"
```Output generated by flux can be tested using `flux envsubst` command:
```shell
$ export cluster_region=eu-central-1
$ kustomize build . | flux envsubst --strict
---
apiVersion: v1
kind: Namespace
metadata:
name: apps
labels:
environment: dev
region: eu-central-1
```## Other Tools
### Helmfile
[helmfile](https://github.com/helmfile/helmfile) is a declarative spec for deploying helm charts. It uses `helm` command
```yaml
helmDefaults:
wait: true
waitForJobs: true
timeout: 600
recreatePods: true
force: truerepositories:
- name: cilium
url: https://helm.cilium.ioreleases:
- name: cilium
namespace: kube-system
chart: cilium/cilium
version: 1.16.0
values:
- ./kubernetes/infrastructure/cilium/app/base/values.yaml
- ./kubernetes/infrastructure/cilium/app/overlays/dev/values.yaml
``````shell
helmfile --quiet --file helmfile.yaml apply --skip-diff-on-install --suppress-diff
```### Boilerplate
For scaffolding automatically out a new fluxcd application from a template defined in a set of files and folders, a tool like [boilerplate](https://github.com/gruntwork-io/boilerplate) from gruntwork-io can be used.
The basic idea behind Boilerplate is that you create a template folder that contains:
- A `boilerplate.yml` file that configures the template, such as the input variables to gather from the user.
- Any number of other files and folders that generate the code you want, using Go templating syntax to fill in those input variables where necessary, do loops, do conditionals, and so on.Install [boilerplate](https://github.com/gruntwork-io/boilerplate) from gruntwork-io
#### Sample Template (fluxcd application)
Template located in `fluxcd-app-template`
```shell
📁
├── 📁 app # base app (helm installation)
│ ├── 📁 base # kustomization base
│ │ ├── helm.yaml # flux helm resources
│ │ ├── kustomization.yaml # kustomization file (base)
│ │ ├── kustomizeconfig.yaml # confiMap generator config
│ │ ├── ns.yaml # namespace manifest
│ │ └── values.yaml # helm values file (base)
│ └── 📁 overlays # kustomization overalys
│ ├── 📁 dev
│ │ ├── kustomization.yaml # kustomization file (overlay)
│ │ └── values.yaml # helm values file (overlay)
│ └── 📁 prod
│ ├── kustomization.yaml
│ └── values.yaml
├── 📁 config # config app (additional configuration)
│ ├── 📁 base
│ └── 📁 overlays
│ ├── 📁 dev
│ └── 📁 prod
├── boilerplate.yml
``````yaml
# boilerplate.yml file
variables:
- name: app_name
description: Enter application name- name: app_namespace
description: Enter application namespace- name: chart_repo_url
description: Enter chart repo URL- name: chart_name
description: Enter Chart name- name: chart_version
description: Enter chart version
```To build a new application from the template. User will be prompted to provide values for all variables included in the `boilerplate.yml`
```shell
boilerplate --template-url --output-folder
```To use variables defined in yaml file instead, define a `vars.yaml` file, containing values for all variables in `boilerplate.yml`
```shell
boilerplate \
--template-url \
--output-folder \
--var-file vars.yml \
--non-interactive
```## References
- https://fluxcd.io/flux/installation/bootstrap/github/
- [Academeez K8s and fluxcd course](https://www.academeez.com/en/course/kubernetes/flux)
- [Repo and videos](https://github.com/ywarezk/academeez-k8s-flux)- [How to Structure Your K8s GitOps Repository at Scale](https://hackernoon.com/how-to-structure-your-k8s-gitops-repository-at-scale-part-1)
- [Kustomize Variants (Overlays)](https://github.com/kubernetes-sigs/kustomize/blob/master/examples/multibases/README.md)
- [Kustomize Components](https://github.com/kubernetes-sigs/kustomize/blob/master/examples/components.md)
- Managing Kubernetes the GitOps way with Flux
- [Repo](https://github.com/moonswitch-workshops/terraform-eks-flux)
- [Video](https://youtu.be/1DuxTlvmaNM?si=SaFfQ30Z1fLAo-Tp)- [Introducing boilerplate](https://blog.gruntwork.io/introducing-boilerplate-6d796444ecf6)
- [Generators [Practical Examples]](https://devopscube.com/kuztomize-configmap-generators/)