kcl-lang / flux-kcl-controller

Flux KCL Controller
https://kcl-lang.io
Apache License 2.0
22 stars 7 forks source link
gitops

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, kustomize-controller and helm-controller to acquire the KCL program from repositories.

kcl-flux

Features

Quick Start

Prerequisites

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 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.

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

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