Skip to content

Commit

Permalink
polish drift-detection-by-argocd (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
howieyuen authored Sep 22, 2022
1 parent 259ae33 commit fedba79
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
30 changes: 23 additions & 7 deletions docs/user_docs/guides/argocd/drift-detection-by-argocd.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Drift Detection by ArgoCD

## 1. Config ArgoCD Plugin with Kusion
## Prerequisite

Install ArgoCD:

```bash
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
```

## Config ArgoCD Plugin with Kusion

ArgoCD has already had some common built-in plugins, including helm, jsonnet, and kustomize.
For KCL, as a brand-new configuration language, if you want to use ArgoCD to complete drift detection,
Expand All @@ -19,7 +28,7 @@ wget -q https://raw.githubusercontent.com/KusionStack/examples/main/kusion/argo-
kubectl -n argocd patch cm/argocd-cm -p "$(cat patch-argocd-cm.yaml)"
```

## 2. Update ArgoCD Deployment
## Update ArgoCD Deployment

After completing the first step, ArgoCD will recognize the Kusion plugin,
but the Kusion plugin has not been loaded into the ArgoCD image.
Expand All @@ -43,7 +52,7 @@ kubectl -n argocd patch deploy/argocd-repo-server -p "$(cat patch-argocd-repo-se
kubectl get pod -n argocd -l app.kubernetes.io/name=argocd-repo-server
```

## 3. Create KCL Project
## Create KCL Project

At this point, the preparation work has been completed, and now the verification process is started.
Here we use example projects from the open-source [Konfig](https://github.com/KusionStack/konfig) library.
Expand Down Expand Up @@ -71,8 +80,12 @@ argocd app create guestbook-test \
--config-management-plugin kusion
```

> Note:If you are using a private repository, you need to configure the private repository access with private key credentials before executing the create command.
> Please refer [Private Repositories](https://argo-cd.readthedocs.io/en/stable/user-guide/private-repositories/#ssh-private-key-credential) for more details.
:::info

If you are using a private repository, you need to configure the private repository access with private key credentials before executing the create command.

Please refer [Private Repositories](https://argo-cd.readthedocs.io/en/stable/user-guide/private-repositories/#ssh-private-key-credential) for more details.
:::

After successfully creating, you can see the following output:

Expand All @@ -91,13 +104,16 @@ Here, you can manually synchronize or set automatic synchronization.
argocd app set guestbook-test --sync-option ApplyOutOfSyncOnly=true
```

> For more information on synchronization strategies, see [Sync Options](https://argo-cd.readthedocs.io/en/stable/user-guide/sync-options/)
:::info

For more information on synchronization strategies, see [Sync Options](https://argo-cd.readthedocs.io/en/stable/user-guide/sync-options/)
:::

Sync succeeded:

![](/img/docs/user_docs/guides/argocd/synced.jpg)

## 4. Config Drift Detection
## Configure Drift Detection

At this point, the ArgoCD monitoring KCL project has been completed, implement configuration drift detection and achieve result consistency.
Let's modify the mirror version of `guestbook-test` to implement configuration changes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# 使用 ArgoCD 进行漂移检查

## 1. 配置 Kusion 插件
## 准备开始

安装 ArgoCD:

```bash
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
```

## 配置 Kusion 插件

目前,ArgoCD 内置了一些常见的配置插件,包括 helm、jsonnet、kustomize。而对于 KCL 来说,作为一门全新的配置语言,想要使用 ArgoCD 实现漂移检查的能力,需要遵循它的插件化的机制,配置 Kusion 插件。具体操作如下:

Expand All @@ -16,8 +25,7 @@ wget -q https://raw.githubusercontent.com/KusionStack/examples/main/kusion/argo-
kubectl -n argocd patch cm/argocd-cm -p "$(cat patch-argocd-cm.yaml)"
```


## 2. 更新 ArgoCD 部署
## 更新 ArgoCD 部署

完成第一步,ArgoCD 就可以识别 Kusion 插件,但 Kusion 插件还没有载入到 ArgoCD 的镜像中。要实现配置漂移检查,需要修改 argocd-repo-server 的 Deployment。

Expand All @@ -39,7 +47,7 @@ kubectl -n argocd patch deploy/argocd-repo-server -p "$(cat patch-argocd-repo-se
kubectl get pod -n argocd -l app.kubernetes.io/name=argocd-repo-server
```

## 3. 创建 KCL 项目
## 创建 KCL 项目

到此,准备工具已经完成,现在开始验证。这里我们使用开源 Konfig 大库中的示例项目。

Expand All @@ -66,7 +74,9 @@ argocd app create guestbook-test \
--config-management-plugin kusion
```

> 注意:如果你正在使用私有仓库,需要先配置私有仓库的访问私钥凭证,再执行创建命令。详细操作,请参见 [Private Repositories](https://argo-cd.readthedocs.io/en/stable/user-guide/private-repositories/#ssh-private-key-credential)
:::info
注意:如果你正在使用私有仓库,需要先配置私有仓库的访问私钥凭证,再执行创建命令。详细操作,请参见 [Private Repositories](https://argo-cd.readthedocs.io/en/stable/user-guide/private-repositories/#ssh-private-key-credential)
:::

创建成功后,可以看到以下输出:

Expand All @@ -84,13 +94,15 @@ application 'guestbook-test' created
argocd app set guestbook-test --sync-option ApplyOutOfSyncOnly=true
```

> 有关同步策略的详细信息,请参见 [Sync Options](https://argo-cd.readthedocs.io/en/stable/user-guide/sync-options/)
:::info
有关同步策略的详细信息,请参见 [Sync Options](https://argo-cd.readthedocs.io/en/stable/user-guide/sync-options/)
:::

同步成功:

![](/img/docs/user_docs/guides/argocd/synced.jpg)

## 4. 配置漂移检查
## 配置漂移检查

到此,已经完成了 ArgoCD 监听 KCL 项目,实现配置漂移检查并实现结果一致性。我们来修改 `guestbook-test` 的镜像版本,实现配置变更。

Expand Down

0 comments on commit fedba79

Please sign in to comment.