使用 Argo CD 配置 crossplane

Argo CDCrossplane是一个很好的组合。Argo CD 提供 GitOps 功能,而 Crossplane 可将任何 Kubernetes 集群转化为所有资源的通用控制平面(Universal Control Plane)。 要使二者正常协同工作,需要一些配置细节。 本文档将帮助您了解这些要求。 建议将 Argo CD 2.4.8 或更高版本与 Crossplane 结合使用。

Argo CD 会将存储在 Git 仓库中的 Kubernetes 资源清单与运行在 Kubernetes 集群(GitOps)中的资源清单同步。 配置 Argo CD 跟踪资源的方式有多种。 使用 crossplane 时,需要将 Argo CD 配置为使用基于 Annotations 的资源跟踪。更多详情请参见 Argo CD docs

使用 crossplane 配置 Argo CD

设置资源跟踪方法

为了使 Argo CD 能够正确跟踪包含 crossplane 相关对象的应用程序资源,需要将其配置为使用 Annotations 机制。

要对其进行配置,请在 argocd Namespace 中编辑 argocd-cm``ConfigMap 如下:

1apiVersion: v1
2kind: ConfigMap
3data:
4  application.resourceTrackingMethod: annotation

设置健康状况

Argo CD 内置了 Kubernetes 资源的健康评估功能。 社区直接在 Argo 的 repository中支持某些检查。例如,“pkg.crossplane.io “中的 “Provider “已经声明式,这意味着无需进一步配置。

Argo CD 还能在每个实例中自定义这些检查,这就是用来为 Provider 的 CRD 提供支持的机制。

要对其进行配置,请编辑 argocd Namespace 中的 argocd-cm``ConfigMap

Note
提供程序配置可能没有状态或status.users字段。

  1apiVersion: v1
  2kind: ConfigMap
  3data:
  4  application.resourceTrackingMethod: annotation
  5  resource.customizations: |
  6    "*.upbound.io/*":
  7      health.lua: |
  8        health_status = {
  9          status = "Progressing",
 10          message = "Provisioning ..."
 11        }
 12
 13        local function contains (table, val)
 14          for i, v in ipairs(table) do
 15            if v == val then
 16              return true
 17            end
 18          end
 19          return false
 20        end
 21
 22        local has_no_status = {
 23          "ProviderConfig",
 24          "ProviderConfigUsage"
 25        }
 26
 27        if obj.status == nil and contains(has_no_status, obj.kind) then
 28          health_status.status = "Healthy"
 29          health_status.message = "Resource is up-to-date."
 30          return health_status
 31        end
 32
 33        if obj.status == nil or obj.status.conditions == nil then
 34          if obj.kind == "ProviderConfig" and obj.status.users ~= nil then
 35            health_status.status = "Healthy"
 36            health_status.message = "Resource is in use."
 37            return health_status
 38          end
 39          return health_status
 40        end
 41
 42        for i, condition in ipairs(obj.status.conditions) do
 43          if condition.type == "LastAsyncOperation" then
 44            if condition.status == "False" then
 45              health_status.status = "Degraded"
 46              health_status.message = condition.message
 47              return health_status
 48            end
 49          end
 50
 51          if condition.type == "Synced" then
 52            if condition.status == "False" then
 53              health_status.status = "Degraded"
 54              health_status.message = condition.message
 55              return health_status
 56            end
 57          end
 58
 59          if condition.type == "Ready" then
 60            if condition.status == "True" then
 61              health_status.status = "Healthy"
 62              health_status.message = "Resource is up-to-date."
 63              return health_status
 64            end
 65          end
 66        end
 67
 68        return health_status
 69
 70    "*.crossplane.io/*":
 71      health.lua: |
 72        health_status = {
 73          status = "Progressing",
 74          message = "Provisioning ..."
 75        }
 76
 77        local function contains (table, val)
 78          for i, v in ipairs(table) do
 79            if v == val then
 80              return true
 81            end
 82          end
 83          return false
 84        end
 85
 86        local has_no_status = {
 87          "Composition",
 88          "CompositionRevision",
 89          "DeploymentRuntimeConfig",
 90          "ControllerConfig"
 91        }
 92        if obj.status == nil and contains(has_no_status, obj.kind) then
 93            health_status.status = "Healthy"
 94            health_status.message = "Resource is up-to-date."
 95          return health_status
 96        end
 97
 98        if obj.status == nil or obj.status.conditions == nil then
 99          return health_status
100        end
101
102        for i, condition in ipairs(obj.status.conditions) do
103          if condition.type == "LastAsyncOperation" then
104            if condition.status == "False" then
105              health_status.status = "Degraded"
106              health_status.message = condition.message
107              return health_status
108            end
109          end
110
111          if condition.type == "Synced" then
112            if condition.status == "False" then
113              health_status.status = "Degraded"
114              health_status.message = condition.message
115              return health_status
116            end
117          end
118
119          if contains({"Ready", "Healthy", "Offered", "Established"}, condition.type) then
120            if condition.status == "True" then
121              health_status.status = "Healthy"
122              health_status.message = "Resource is up-to-date."
123              return health_status
124            end
125          end
126        end
127
128        return health_status    

设置资源排除

Crossplane 提供商会为其处理的每个托管资源(MR)生成一个 “ProviderConfigUsage”。 该资源用于表示 MR 与 ProviderConfig 之间的关系,以便控制器在删除 ProviderConfig 时将其用作 Finalizer。 Crossplane 的最终用户不应与该资源交互。

随着资源和类型数量的增加,Argo CD UI 的反应能力也会受到影响。 为减少资源数量,我们建议在 Argo CD UI 中隐藏所有 ProviderConfigUsage 资源。

要配置资源排除,请按如下方式编辑 argocd Namespace 中的 argocd-cm``ConfigMap :

1apiVersion: v1
2kind: ConfigMap
3data:
4    resource.exclusions: |
5      - apiGroups:
6        - "*"
7        kinds:
8        - ProviderConfigUsage      

使用 "*" 作为 apiGroups 将使该机制适用于所有 crossplane Providerers。

提高 k8s 客户端 QPS

随着控制平面上 CRD 数量的增加,Argo CD 应用程序控制器需要向 Kubernetes API 发送的查询量也会增加。 如果出现这种情况,您可以增加 Argo CD Kubernetes 客户端的速率限制。

将环境变量 ARGOCD_K8S_CLIENT_QPS 设为 300,以提高与大量 CRD 的兼容性。

ARGOCD_K8S_CLIENT_QPS的默认值是 50,修改该值也会更新ARGOCD_K8S_CLIENT_BURST,因为它的默认值是 ARGOCD_K8S_CLIENT_QPS` x 2。