3.4. 启用创建聚合集群角色
要为集群范围的 Argo CD Application CD 实例的 Argo CD Application Controller 组件启用聚合集群角色,您必须通过编辑 Argo CD 自定义资源(CR)的 YAML 文件来配置对应的字段。
流程
在 Argo CD CR 中,将
.spec.aggregatedClusterRoles
字段的值设置为true
:Argo CD CR 示例
apiVersion: argoproj.io/v1beta1 kind: ArgoCD metadata: name: example 1 namespace: spring-petclinic 2 # ... spec: aggregatedClusterRoles: true 3 # ...
输出示例
argocd.argoproj.io/example configured
运行以下命令,验证集群范围的 Argo CD 实例的
Status
字段显示为Phase: Available
:$ oc describe argocd.argoproj.io/example -n spring-petclinic
输出示例
Name: example Namespace: spring-petclinic Labels: <none> Annotations: <none> API Version: argoproj.io/v1beta1 Kind: ArgoCD Metadata: Creation Timestamp: 2024-08-14T08:20:53Z Finalizers: argoproj.io/finalizer Generation: 3 Resource Version: 60437 UID: 57940e54-d60b-4c1a-bc4a-85c81c63ab69 Spec: Aggregated Cluster Roles: true ... Status: Application Controller: Running Application Set Controller: Unknown Phase: Available 1 Redis: Running Repo: Running Server: Running Sso: Unknown Events: <none>
- 1
Available
状态表示集群范围的 Argo CD 实例处于健康状态且可用。
注意Red Hat OpenShift GitOps Operator 创建以下默认集群角色并管理它们:
-
<argocd_name>-<argocd_namespace>-argocd-application-controller
聚合集群角色 -
<argocd_name>-<argocd_namespace>-argocd-application-controller-view
-
<argocd_name>-<argocd_namespace>-argocd-application-controller-admin
运行以下命令,验证 Operator 是否为 Argo CD Application Controller 和 Argo CD 服务器组件创建了默认的集群角色和集群角色绑定:
$ oc get ClusterRoles -l app.kubernetes.io/part-of=argocd
输出示例
NAME CREATED AT example-spring-petclinic-argocd-application-controller 2024-08-14T08:20:58Z example-spring-petclinic-argocd-application-controller-admin 2024-08-14T09:08:38Z example-spring-petclinic-argocd-application-controller-view 2024-08-14T09:08:38Z example-spring-petclinic-argocd-server 2024-08-14T08:20:59Z
$ oc get ClusterRoleBindings -l app.kubernetes.io/part-of=argocd
输出示例
NAME ROLE AGE example-spring-petclinic-argocd-application-controller ClusterRole/example-spring-petclinic-argocd-application-controller 54m example-spring-petclinic-argocd-server ClusterRole/example-spring-petclinic-argocd-server 54m
不会创建
view
和admin
集群角色的集群角色绑定。这是因为view
和admin
集群角色仅将权限添加到聚合的集群角色中,而不直接配置 Argo CD Application Controller 的权限。提示或者,您可以使用 OpenShift Container Platform Web 控制台从 Administrator 视角进行验证。您可以分别进入 User Management
Roles and User Management RoleBindings。您可以搜索具有 app.kubernetes.io/part-of:argocd
标签的集群角色和集群角色绑定。运行以下命令,验证是否通过检查创建的角色输出的权限创建了聚合的集群角色:
$ oc get ClusterRole/<cluster_role_name> -o yaml 1
- 1
- 将
<cluster_role_name
> 替换为所创建的角色的名称。
聚合集群角色的输出示例
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: annotations: argocds.argoproj.io/name: example argocds.argoproj.io/namespace: spring-petclinic kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"argoproj.io/v1beta1","kind":"ArgoCD","metadata":{"annotations":{},"name":"example","namespace":"spring-petclinic"},"spec":{"aggregatedClusterRoles":true}} rbac.authorization.kubernetes.io/autoupdate: "true" creationTimestamp: "2024-08-14T08:20:58Z" labels: app.kubernetes.io/managed-by: spring-petclinic app.kubernetes.io/name: example app.kubernetes.io/part-of: argocd name: example-spring-petclinic-argocd-application-controller 1 resourceVersion: "78640" uid: aeeb2ef5-b531-4fe3-a61a-b5ad8dd8ca6e aggregationRule: 2 clusterRoleSelectors: - matchLabels: app.kubernetes.io/managed-by: spring-petclinic argocd/aggregate-to-controller: "true" rules: [] 3
view
集群角色的输出示例apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: annotations: argocds.argoproj.io/name: example argocds.argoproj.io/namespace: spring-petclinic kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"argoproj.io/v1beta1","kind":"ArgoCD","metadata":{"annotations":{},"name":"example","namespace":"spring-petclinic"},"spec":{"aggregatedClusterRoles":true}} creationTimestamp: "2024-08-14T09:59:14Z" labels: 1 app.kubernetes.io/managed-by: spring-petclinic app.kubernetes.io/name: example app.kubernetes.io/part-of: argocd argocd/aggregate-to-controller: "true" name: example-spring-petclinic-argocd-application-controller-view 2 resourceVersion: "78639" uid: 068b8867-7a0c-4af3-a17a-0560a00eba41 rules: 3 - apiGroups: - '*' resources: - '*' verbs: - get - list - watch - nonResourceURLs: - '*' verbs: - get - list
admin
集群角色的输出示例apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: annotations: argocds.argoproj.io/name: example argocds.argoproj.io/namespace: spring-petclinic kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"argoproj.io/v1beta1","kind":"ArgoCD","metadata":{"annotations":{},"name":"example","namespace":"spring-petclinic"},"spec":{"aggregatedClusterRoles":true}} rbac.authorization.kubernetes.io/autoupdate: "true" creationTimestamp: "2024-08-14T09:59:15Z" labels: 1 app.kubernetes.io/managed-by: spring-petclinic app.kubernetes.io/name: example app.kubernetes.io/part-of: argocd argocd/aggregate-to-controller: "true" name: example-spring-petclinic-argocd-application-controller-admin 2 resourceVersion: "78642" uid: e2d35b6f-0832-4993-8b24-915a725454f9 aggregationRule: 3 clusterRoleSelectors: - matchLabels: app.kubernetes.io/managed-by: spring-petclinic argocd/aggregate-to-admin: "true" rules: null 4
提示或者,您可以使用 OpenShift Container Platform Web 控制台从 Administrator 视角进行验证。您可以进入 User Management
Roles,使用 Filter 选项,选择 Cluster-wide Roles,并搜索聚合的集群角色, 查看
,以及admin
集群角色。您必须打开集群角色来检查详情和配置。作为集群管理员,您可以创建一个或多个用户定义的集群角色,并为 Argo CD Application Controller 配置用户定义的权限。
其他资源