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
Create a cluster using the following command:
k3d cluster create
Clone this repository to local:
git clone https://github.com/kcl-lang/flux-kcl-controller.git
Enter the root directory of this repository:
cd flux-kcl-controller
Install kcl-controller into the cluster:
make deploy
Take 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-deployment
Use 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 28s
The 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 4s
flux-kcl-controller
creates a nginx-deployment-1
according to the KCL program in the repository.