|
| 1 | +--- |
| 2 | +id: flux-cd |
| 3 | +sidebar_label: Flux-KCL-Controller |
| 4 | +--- |
| 5 | + |
| 6 | +# Flux KCL Controller |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +The kcl-controller is a component developed for the integration of [KCL](https://github.com/kcl-lang/kcl) and [Flux](https://github.com/fluxcd/flux2), designed to orchestrate continuous delivery pipelines for infrastructure and workloads defined with KCL based on the [source-controller](https://github.com/fluxcd/source-controller) to acquire the KCL program from repositories. |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +## Features |
| 15 | + |
| 16 | +- Periodically monitor git repositories that store KCL programs and reconcile k8s cluster status according to changes in git repositories. |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +### Prerequisites |
| 21 | + |
| 22 | +- k3d: used to create a k8s cluster for testing, if you already have a k8s cluster, you can skip ignore this. |
| 23 | +- Kustomize |
| 24 | +- Kubectl |
| 25 | + |
| 26 | +### Create a test k8s cluster |
| 27 | + |
| 28 | +Create a cluster using the following command: |
| 29 | + |
| 30 | +```shell |
| 31 | +k3d cluster create |
| 32 | +``` |
| 33 | + |
| 34 | +### Download kcl-controller and install it into the cluster |
| 35 | + |
| 36 | +Clone this repository to local: |
| 37 | + |
| 38 | +```shell |
| 39 | +git clone https://github.com/kcl-lang/flux-kcl-controller.git |
| 40 | +``` |
| 41 | + |
| 42 | +Enter the root directory of this repository: |
| 43 | + |
| 44 | +```shell |
| 45 | +cd flux-kcl-controller |
| 46 | +``` |
| 47 | + |
| 48 | +Install kcl-controller into the cluster: |
| 49 | + |
| 50 | +```shell |
| 51 | +make deploy |
| 52 | +``` |
| 53 | + |
| 54 | +### Monitor a git repository |
| 55 | + |
| 56 | +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 kcl-controller to deploy this program. |
| 57 | + |
| 58 | +Define a `GitRepository` object through the `gitrepo.yaml` file to monitor the repository: |
| 59 | + |
| 60 | +```yaml |
| 61 | +apiVersion: source.toolkit.fluxcd.io/v1 |
| 62 | +kind: GitRepository |
| 63 | +metadata: |
| 64 | + name: kcl-deployment |
| 65 | + namespace: source-system |
| 66 | +spec: |
| 67 | + interval: 30s |
| 68 | + url: https://github.com/awesome-kusion/kcl-deployment.git |
| 69 | + ref: |
| 70 | + branch: main |
| 71 | +--- |
| 72 | +apiVersion: krm.kcl.dev.fluxcd/v1alpha1 |
| 73 | +kind: KCLRun |
| 74 | +metadata: |
| 75 | + name: kcl-deployment |
| 76 | + namespace: source-system |
| 77 | +spec: |
| 78 | + sourceRef: |
| 79 | + kind: GitRepository |
| 80 | + name: kcl-deployment |
| 81 | +``` |
| 82 | +
|
| 83 | +Use the command `kubectl apply -f gitrepo.yaml` to deploy the object to the cluster. |
| 84 | + |
| 85 | +### View the deployment result |
| 86 | + |
| 87 | +Use the command `kubectl get deployment` to view the deployment result: |
| 88 | + |
| 89 | +```shell |
| 90 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 91 | +nginx-deployment 1/1 1 0 28s |
| 92 | +``` |
| 93 | + |
| 94 | +The `nginx-deployment` is deployed successfully. |
| 95 | + |
| 96 | +### Update the KCL program in the repository |
| 97 | + |
| 98 | +We can update the `Deployment` in the cluster by modifying the KCL program in the repository. |
| 99 | + |
| 100 | +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. |
| 101 | + |
| 102 | +The changes can be referred to: [nginx:1.7.7 deployment](https://github.com/awesome-kusion/kcl-deployment/commit/dc8b2aa70b1b47bef0637212ea184792b8c43449) -> [nginx:1.7.8 deployment](https://github.com/awesome-kusion/kcl-deployment/commit/f257a71fdff6cb9190f49c1dbf5fa4496d7b3cb2) |
| 103 | + |
| 104 | +Use the command `kubectl get deployment` to view the deployment result: |
| 105 | + |
| 106 | +```shell |
| 107 | +NAME READY UP-TO-DATE AVAILABLE AGE |
| 108 | +nginx-deployment 1/1 1 1 20m |
| 109 | +nginx-deployment-1 1/1 1 0 4s |
| 110 | +``` |
| 111 | + |
| 112 | +kcl-controller creates a `nginx-deployment-1` according to the KCL program in the repository. |
| 113 | + |
| 114 | +## Roadmap |
| 115 | + |
| 116 | +- Add KCL OCI Registry Controller to support KCL programs stored in OCI registry. |
0 commit comments