What’s up folks?
This is a two-part post, so if you missed part 1, I truly recommend you to read it: How to accelerate the Kubernetes cluster configuration using FluxCD – Part1.
In the last post, we’ve seen how to use FluxCD to install global components to our Kubernetes cluster and now it’s time to take the next step and demonstrate how we can enable specific capabilities per cluster.
Recalling the repository structure
Before beginning, let’s review the structure we are using in the GitOps repository to meet the requirement of being able to install some components for all clusters, while installing others only if necessary.
With that in mind, we have adopted the pattern of global and specific components, so two folders have been created, one for each role:
- global-config: the manifests included in this folder will be applied automatically during flux installation
- extra-capabilities: the manifests included in this folder will only be applied if they are explicitly declared
The repo used for this lab is available on: https://github.com/diego7marques/k8s-base-config
Creating the manifests
For this example, we are considering that Crossplane is an component that we only want to install it when needed. So let’s create a new folder called crossplane-operator inside the extra-capabilities and include the following manifests:
#### helmrepository.yml
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmRepository
metadata:
## Name of the repository.
## Same value used on "helm repo add [NAME]" command.
name: crossplane-stable
namespace: flux-system
spec:
## Interval that you want flux search for new versions.
interval: 5m0s
## Url field must be the endpoint of the helmrepository.
## Same value used on "helm repo add [NAME] [URL]" command.
url: https://charts.crossplane.io/stable
#### helmrelease.yml
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
## Name of the helm installation.
## Same value used on "helm install [NAME]" command.
name: crossplane
namespace: flux-system
spec:
## Interval that you want to apply the lastest config in case new version is available.
interval: 5m0s
chart:
spec:
## Chart field must be the name of the helmchart.
## Same value used on "helm install [NAME] [CHART]" command.
chart: crossplane-stable/crossplane
## Version field must be the chart version you want to install
## Same value used on "--version" parameter.
version: '1.*'
## SourceRef must match the same name used in the helmrepository.yml file
sourceRef:
kind: HelmRepository
name: crossplane-stable
install:
createNamespace: true
targetNamespace: crossplane-system
### kustomization.yml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- helmrepository.yml
- helmrelease.yml
Installing the specific component
Now that we have our component manifests created, we’ll perform the following commands to install it:
## Use the reconcile to force flux to download the lastest version of repository
flux reconcile source git flux-system -n flux-system
## The command will install the crossplane to the desired cluster
flux create kustomization crossplane \
--source=GitRepository/flux-system \
--path="./extra-capabitilies/crossplane-operator" \
--prune=true \
--interval=60m \
--wait=true \
--health-check-timeout=3m
When the command finishes, it means that the component is already installed 😃 If you want to install other component, you just need to change the value of path parameter.
Here is a quick demonstration:
Conclusion
Once again flux shows his potential of making our day easier. If you combine the knowledge acquired in both parts, you can already manage your clusters at scale, in a standardized and manageable way. It will help you not only during the configuration process, but also in day-to-day tasks of maintaining end evolving the components.
Discover more from contains(cloud)
Subscribe to get the latest posts sent to your email.
Be First to Comment