The flux-kcl-controller is a component developed for the integration of KCL and Flux, designed to orchestrate continuous delivery pipelines for infrastructure and workloads defined with KCL based on the source-controller, kustomize-controller and helm-controller to acquire the KCL program from repositories.
- Periodically monitor git repositories that store KCL programs and reconcile k8s cluster status according to changes in git repositories.
- k3d: used to create a k8s cluster for testing, if you already have a k8s cluster, you can skip ignore this.
- Kustomize
- Kubectl
Install WSL (Windows Subsystem for Linux):
- Open PowerShell as Administrator and run:
wsl --install - Restart your computer.
- Open WSL terminal and install required tools:
sudo apt update
sudo apt install make kubectl git
# Install k3d
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
# Install kustomize
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
sudo mv kustomize /usr/local/bin/
Create a cluster using the following command:
k3d cluster createClone this repository to local:
git clone https://github.com/kcl-lang/flux-kcl-controller.gitEnter the root directory of this repository:
cd flux-kcl-controllerInstall kcl-controller into the cluster:
make deployTake the GitHub repository https://github.com/awesome-kusion/kcl-deployment as an example. This repository stores a KCL program that defines a Deployment. We will use flux-kcl-controller to deploy this program.
Define a GitRepository object through the gitrepo.yaml file to monitor the repository:
apiVersion: source.toolkit.fluxcd.io/v1
kind: GitRepository
metadata:
name: kcl-deployment
namespace: source-system
spec:
interval: 30s
url: https://github.com/awesome-kusion/kcl-deployment.git
ref:
branch: main
---
apiVersion: krm.kcl.dev.fluxcd/v1alpha1
kind: KCLRun
metadata:
name: kcl-deployment
namespace: source-system
spec:
sourceRef:
kind: GitRepository
name: kcl-deploymentUse the command kubectl apply -f gitrepo.yaml to deploy the object to the cluster.
Use the command kubectl get deployment to view the deployment result:
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 1/1 1 0 28sThe nginx-deployment is deployed successfully.
We can update the Deployment in the cluster by modifying the KCL program in the repository.
Change the version of nginx from 1.7.7 to 1.7.8 and the name of deployment to nginx-deployment-1, and commit to the main branch.
The changes can be referred to: nginx:1.7.7 deployment -> nginx:1.7.8 deployment
Use the command kubectl get deployment to view the deployment result:
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 1/1 1 1 20m
nginx-deployment-1 1/1 1 0 4sflux-kcl-controller creates a nginx-deployment-1 according to the KCL program in the repository.
