Skip to content

Commit 4236caf

Browse files
committed
fix: fix fluxcd guide
Signed-off-by: zongz <zongzhe1024@163.com>
1 parent 665cd7c commit 4236caf

File tree

4 files changed

+119
-138
lines changed

4 files changed

+119
-138
lines changed

docs/user_docs/guides/gitops/1-argocd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: gitops-quick-start
3-
sidebar_label: Quick Start
3+
sidebar_label: Implement GitOps with KCL and ArgoCD
44
---
55

66
# Quick Start
Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,114 @@
11
---
2-
id: flux-cd
3-
sidebar_label: Flux-KCL-Controller
2+
id: gitops-with-fluxcd
3+
sidebar_label: Implement GitOps with KCL and FluxCD
44
---
55

6-
# Flux KCL Controller
6+
# Quick Start
77

88
## Introduction
99

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.
10+
### What is GitOps
1111

12-
![](/img/docs/user_docs/guides/cd-integration/kcl-flux.png)
12+
GitOps is a modern way to do continuous delivery. Its core idea is to have a Git repository which contains environmental and application configurations. An automated process is also needed for sync the config to cluster.
1313

14-
## Features
14+
By changing the files in repository, developers can apply the applications automatically. The benefits of applying GitOps include:
1515

16-
- Periodically monitor git repositories that store KCL programs and reconcile k8s cluster status according to changes in git repositories.
16+
- Increased productivity. Continuous delivery can speed up the time of deployment.
17+
- Lower the barrier for developer to deploy. By pushing code instead of container configuration, developers can easily deploy Kubernetes without knowing its internal implementation.
18+
- Trace the change records. Managing the cluster with Git makes every change traceable, enhancing the audit trail.
19+
- Recover the cluster with Git's rollback and branch.
1720

18-
## Quick Start
21+
### GitOps with KCL and FluxCD
1922

20-
### Prerequisites
23+
Benefits of Using KCL and FluxCD Together:
2124

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+
- KCL can help us **simplify complex Kubernetes deployment configuration files**, reduce the error rate of manually writing YAML files, and improve code readability and maintainability.
26+
- FluxCD can **automate** the deployment of Kubernetes applications, achieve continuous deployment, and provide comprehensive monitoring and control functions.
27+
- By combining KCL and FluxCD, deployment efficiency can be improved, errors reduced, and management and monitoring of Kubernetes applications strengthened.
28+
- The combination of KCL and FluxCD can also help us achieve **Infrastructure as Code (IaC)**, simplify application deployment and management, and better implement DevOps principles.
2529

26-
### Create a test k8s cluster
30+
With GitOps, developer and operation teams can manage application deployment and configuration by modifying KCL code and generating YAML files. The GitOps toolchain will automatically synchronize the changes to the Kubernetes cluster, enabling continuous deployment and ensuring consistency. If there are issues, the GitOps toolchain can be used to quickly rollback.
2731

28-
Create a cluster using the following command:
32+
### Flux-KCL-Controller
2933

30-
```shell
31-
k3d cluster create
32-
```
34+
flux-kcl-controller is a component that integrates [KCL](https://github.com/kcl-lang/kcl) and [Flux](https://github.com/fluxcd/flux2), which is mainly used to define infrastructure and workloads based on KCL programs stored in git/oci repositories, and to achieve continuous delivery of infrastructure and workloads through [source-controller](
3335

34-
### Download kcl-controller and install it into the cluster
36+
![](/img/docs/user_docs/guides/cd-integration/kcl-flux.png)
3537

36-
Clone this repository to local:
38+
## Prerequisite
3739

38-
```shell
39-
git clone https://github.com/kcl-lang/flux-kcl-controller.git
40-
```
40+
- Install [KCL](https://kcl-lang.io/docs/user_docs/getting-started/install)
4141

42-
Enter the root directory of this repository:
42+
## Quick Start
43+
44+
### 1. Install Kubernetes and GitOps Tools
45+
46+
#### Configure Kubernetes Cluster and FluxCD Controller
4347

44-
```shell
45-
cd flux-kcl-controller
48+
- Install [K3d](https://github.com/k3d-io/k3d) to create a default cluster.
49+
50+
```bash
51+
k3d cluster create mycluster
4652
```
4753

48-
Install kcl-controller into the cluster:
54+
- Install Flux KCL Controller
4955

50-
```shell
51-
make deploy
56+
```bash
57+
git clone https://github.com/kcl-lang/flux-kcl-controller.git && cd flux-kcl-controller && make deploy
5258
```
5359

54-
### Monitor a git repository
60+
- Check if the fluxcd controller container is initialized and running by using the `kubectl get` command.
61+
62+
```bash
63+
kubectl get pod -n source-system -l app=kcl-controller
64+
```
5565

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.
66+
### 2. Write Flux-KCL-Controller Configuration File
5767

58-
Define a `GitRepository` object through the `gitrepo.yaml` file to monitor the repository:
68+
Create a `GitRepository` object for `flux-kcl-controller` to monitor the KCL program stored in the git repository. For example, we use the flask demo in [“Implementing GitOps using Github, Argo CD, and KCL to Simplify DevOps”](https://kcl-lang.io/blog/2023-07-31-kcl-github-argocd-gitops/#3-get-the-application-code) as an example. We create a `GitRepository` object in the `flux-kcl-controller` repository to monitor the KCL program stored in the git repository. Save the following content in the file `gitrepo.yaml`.
5969

6070
```yaml
6171
apiVersion: source.toolkit.fluxcd.io/v1
6272
kind: GitRepository
6373
metadata:
6474
name: kcl-deployment
65-
namespace: source-system
75+
namespace: default
6676
spec:
67-
interval: 30s
68-
url: https://github.com/awesome-kusion/kcl-deployment.git
77+
interval: 10s # Check every 10 seconds
78+
url: https://github.com/kcl-lang/flask-demo-kcl-manifests.git
6979
ref:
70-
branch: main
80+
branch: main # Monitor the main branch
7181
---
7282
apiVersion: krm.kcl.dev.fluxcd/v1alpha1
7383
kind: KCLRun
7484
metadata:
75-
name: kcl-deployment
76-
namespace: source-system
85+
name: kcl-git-controller
86+
namespace: default
7787
spec:
7888
sourceRef:
7989
kind: GitRepository
8090
name: kcl-deployment
8191
```
8292
83-
Use the command `kubectl apply -f gitrepo.yaml` to deploy the object to the cluster.
93+
Apply the `GitRepository` object to the cluster by running the `kubectl apply -f gitrepo.yaml` command.
8494

85-
### View the deployment result
95+
### 3. Check the Deployment Result
8696

87-
Use the command `kubectl get deployment` to view the deployment result:
97+
Check the deployment result by running the `kubectl get deployments` command.
8898

89-
```shell
90-
NAME READY UP-TO-DATE AVAILABLE AGE
91-
nginx-deployment 1/1 1 0 28s
99+
```
100+
kubectl get deployments
92101
```
93102
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:
103+
You can see the result, and the deployment is successful.
105104
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
105+
```
106+
NAME READY UP-TO-DATE AVAILABLE AGE
107+
flask-demo 1/1 1 1 17d
110108
```
111109
112-
kcl-controller creates a `nginx-deployment-1` according to the KCL program in the repository.
113-
114-
## Roadmap
110+
### 4. More
115111
116-
- Add KCL OCI Registry Controller to support KCL programs stored in OCI registry.
112+
- [FluxCD](https://toolkit.fluxcd.io/)
113+
- [Flux Source Controller](https://fluxcd.io/flux/components/source/)
114+
- [GitRepositrory](https://fluxcd.io/flux/components/source/gitrepositories/)

i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/gitops/1-argocd.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: gitops-quick-start
3-
sidebar_label: 快速开始
3+
sidebar_label: 使用 ArgoCD 支持 KCL 实现 GitOps
44
---
55

66
# 快速开始
Lines changed: 57 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,111 @@
11
---
2-
id: flux-cd
3-
sidebar_label: Flux-KCL-Controller
2+
id: gitops-with-fluxcd
3+
sidebar_label: 使用 flux-kcl-controller 支持 KCL 与 FluxCD 实现 GitOps
44
---
55

6-
# Flux KCL Controller
6+
# 快速开始
77

8-
## 介绍
8+
## 简介
99

10-
kcl-controller 是一个组件,用于集成 [KCL](https://github.com/kcl-lang/kcl)[Flux](https://github.com/fluxcd/flux2), 主要用来根据存储在 git/oci 仓库中的 KCL 程序定义的基础设施和工作负载,通过 [source-controller](https://github.com/fluxcd/source-controller) 获取 KCL 程序,实现基础设施和工作负载的持续交付。
10+
### 什么是 GitOps
1111

12-
![](/img/docs/user_docs/guides/cd-integration/kcl-flux.png)
12+
GitOps 是一种实现持续交付的现代方式。它的核心思想是拥有一个包含环境和应用程序配置的 Git 存储库。通过更改应用存储库中的文件,可以自动部署应用程序。应用 GitOps 的好处包括:
1313

14-
## 特性
14+
- 提高生产力,持续交付可以加快部署时间。
15+
- 降低开发人员部署的障碍。通过推送代码而不是容器配置,开发人员可以在不知道其内部实现的情况下轻松部署 Kubernetes 集群和应用。
16+
- 追踪变更记录。使用 Git 管理配置使每一项更改都具有可跟踪性,从而增强审计跟踪。
1517

16-
- 定期监控存储 KCL 程序的 git/oci 仓库,并根据 git 仓库中的变化,调谐 k8s 集群状态。
18+
### KCL 与 FluxCD 一起使用
1719

18-
## 快速开始
20+
[KCL](https://github.com/kcl-lang/kcl)[FluxCD](https://github.com/fluxcd/flux2) 等 GitOps 工具一起使用具有如下好处:
1921

20-
### 前提条件
22+
- 通过 KCL 语言的[抽象能力](/docs/user_docs/guides/abstraction)和可编程能力可以帮助我们**简化复杂的 Kubernetes 部署配置文件**,降低手动编写 YAML 文件的错误率,消除多余的配置模版,提升多环境多租户的配置扩展能力,同时提高配置的可读性和可维护性。
23+
- KCL 允许开发人员以声明式的方式定义应用程序所需的资源,通过将 KCL 和 FluxCD 相结合可以帮助我们更好地实现**基础设施即代码(IaC)**,提高部署效率,简化应用程序的配置管理。
24+
- FluxCD 可以**自动化**地实现应用程序的连续部署,并提供友好的可视化界面。
2125

22-
- k3d: 用于创建测试用的 k8s 集群,如果你已经有了 k8s 集群,可以忽略这一步。
23-
- Kustomize
24-
- Kubectl
26+
使用 GitOps,开发人员和运维团队可以通过分别修改应用和配置代码来管理应用程序的部署,GitOps 工具链将自动同步对配置的更改,从而实现持续部署并确保一致性。如果出现问题,可以使用 GitOps 工具链快速回滚。
2527

26-
### 创建测试用的 k8s 集群
28+
### Flux-KCL-Controller
2729

28-
使用`mycluster.yaml`创建集群:
30+
kcl-controller 是一个组件,用于集成 [KCL](https://github.com/kcl-lang/kcl)[Flux](https://github.com/fluxcd/flux2), 主要用来根据存储在 git/oci 仓库中的 KCL 程序定义的基础设施和工作负载,通过 [source-controller](https://github.com/fluxcd/source-controller) 获取 KCL 程序,实现基础设施和工作负载的持续交付。
2931

30-
```yaml
31-
apiVersion: k3d.io/v1alpha2
32-
kind: Simple
33-
name: mycluster
34-
servers: 1
35-
agents: 2
36-
```
37-
通过如下命令创建集群:
32+
![](/img/docs/user_docs/guides/cd-integration/kcl-flux.png)
3833

39-
```shell
40-
k3d cluster create -c mycluster.yaml
41-
```
34+
## 先决条件
4235

43-
### 下载 kcl-controller 并且安装到集群中
36+
- 安装 [KCL](https://kcl-lang.io/docs/user_docs/getting-started/install)
4437

45-
clone 本仓库到本地:
38+
## 快速开始
4639

47-
```shell
48-
git clone https://github.com/kcl-lang/kcl-controller.git
49-
```
40+
### 1. 安装 Kubernetes 和 GitOps 工具
5041

51-
进入到本仓库的根目录:
42+
#### 配置 Kubernetes 集群和 FluxCD 控制器
5243

53-
```shell
54-
cd kcl-controller
44+
- 安装 [K3d](https://github.com/k3d-io/k3d) 并创建一个集群
45+
46+
```bash
47+
k3d cluster create mycluster
5548
```
5649

57-
将 kcl-controller 安装到集群中:
50+
> 注意:你可以在此方案中使用其他方式创建您自己的 Kubernetes 集群,如 kind, minikube 等。
51+
52+
- 安装 Flux KCL Controller
5853

59-
```shell
60-
make deploy
54+
```bash
55+
git clone https://github.com/kcl-lang/flux-kcl-controller.git && cd flux-kcl-controller && make deploy
6156
```
6257

63-
### 监控一个 git 仓库
58+
- 通过 `kubectl get` 命令查看 fluxcd 控制器容器是否初始化完成进入运行(Running)状态。
6459

65-
我们以仓库 https://github.com/awesome-kusion/kcl-deployment 为例,该仓库中存储了一个 KCL 程序,该程序定义了一个 Deployment,我们将使用 kcl-controller 来部署该程序。
60+
```bash
61+
kubectl get pod -n source-system -l app=kcl-controller
62+
```
6663

67-
通过 `gitrepo.yaml` 文件,定义一个 `GitRepository` 对象,用来监控该仓库:
64+
### 2. 编写 Flux-KCL-Controller 配置文件
65+
66+
[《使用 Github、Argo CD 和 KCL 实现 GitOps 以简化 DevOps》](https://kcl-lang.io/zh-CN/blog/2023-07-31-kcl-github-argocd-gitops/) 中的 flask demo 为例,我们在 `flux-kcl-controller` 仓库中创建一个 `GitRepository` 对象,用于监控存储在 git 仓库中的 KCL 程序。将一下内容保存在文件 `gitrepo.yaml` 中。
6867

6968
```yaml
7069
apiVersion: source.toolkit.fluxcd.io/v1
7170
kind: GitRepository
7271
metadata:
7372
name: kcl-deployment
74-
namespace: source-system
73+
namespace: default
7574
spec:
76-
interval: 30s # 每隔 30s 检查一次仓库
77-
url: https://github.com/awesome-kusion/kcl-deployment.git
75+
interval: 10s # 每隔 10 秒检查
76+
url: https://github.com/kcl-lang/flask-demo-kcl-manifests.git
7877
ref:
7978
branch: main # 监控 main 分支
8079
---
8180
apiVersion: krm.kcl.dev.fluxcd/v1alpha1
8281
kind: KCLRun
8382
metadata:
84-
name: kcl-deployment
85-
namespace: source-system
83+
name: kcl-git-controller
84+
namespace: default
8685
spec:
8786
sourceRef:
8887
kind: GitRepository
8988
name: kcl-deployment
9089
```
9190
92-
使用命令 `kubectl apply -f gitrepo.yaml` 将该对象部署到集群中
91+
通过命令 `kubectl apply -f gitrepo.yaml` 部署对象到集群
9392

94-
### 查看部署结果
93+
### 3. 查看部署结果
9594

96-
使用命令 `kubectl get deployment` 查看部署结果:
95+
通过 `kubectl get deployments` 命令查看 python flask demo 部署结果。
9796

98-
```shell
99-
NAME READY UP-TO-DATE AVAILABLE AGE
100-
nginx-deployment 1/1 1 0 28s
10197
```
102-
103-
可以看到,kcl-controller 根据仓库中的 KCL 程序,创建了一个 Deployment。
104-
105-
### 更新仓库中的 KCL 程序
106-
107-
我们可以通过修改仓库中的 KCL 程序,来更新集群中的 Deployment。
108-
109-
修改仓库中的 KCL 程序,将 nginx 的版本从 `1.7.7` 修改为 `1.7.8`,将`deployment`的名字改为 `nginx-deployment-1`,并且提交到 main 分支。
110-
111-
具体变化可以参考:
112-
[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)
113-
114-
115-
使用命令 `kubectl get deployment` 查看部署结果:
116-
117-
```shell
118-
NAME READY UP-TO-DATE AVAILABLE AGE
119-
NAME READY UP-TO-DATE AVAILABLE AGE
120-
nginx-deployment 1/1 1 1 20m
121-
nginx-deployment-1 1/1 1 0 4s
98+
kubectl get deployments
12299
```
123100
124-
可以看到,kcl-controller 根据仓库中的 KCL 程序,创建了一个 nginx-deployment-1。
101+
可以看到结果,部署成功
102+
```
103+
NAME READY UP-TO-DATE AVAILABLE AGE
104+
flask-demo 1/1 1 1 17d
105+
```
125106
126-
## 未来工作
107+
### 4. 更多内容
127108
128-
- 添加 KCL OCI Registry Controller,用于支持存储在 OCI 仓库中的 KCL 程序。
109+
- [FluxCD 官方文档](https://toolkit.fluxcd.io/)
110+
- [Flux Source Controller 官方文档](https://fluxcd.io/flux/components/source/)
111+
- [GitRepositrory](https://fluxcd.io/flux/components/source/gitrepositories/)

0 commit comments

Comments
 (0)