Skip to content

kcl-lang/flux-kcl-controller

Repository files navigation

Flux KCL controller

English | 简体中文

FOSSA Status

Introduction

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 to acquire the KCL program from repositories.

kcl-flux

Features

  • Periodically monitor git repositories that store KCL programs and reconcile k8s cluster status according to changes in git repositories.

Quick Start

Prerequisites

  • 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 test k8s cluster

Create a cluster using the following command:

k3d cluster create

Download kcl-controller and install it into the cluster

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

Monitor a git repository

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.

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.

View the deployment result

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.

Update the KCL program in the repository

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

kcl-controller creates a nginx-deployment-1 according to the KCL program in the repository.