Argo CD 实例


Red Hat OpenShift GitOps 1.14

安装和部署 Argo CD 实例,使用 Argo CD 实例启用通知,并配置 NotificationsConfiguration CR

Red Hat OpenShift Documentation Team

摘要

本文档提供了有关安装和部署 Argo CD 实例以管理集群配置或部署应用程序的说明。它还讨论了如何为 Argo CD 实例启用通知并配置 NotificationsConfiguration 自定义资源(CR)。

第 1 章 设置 Argo CD 实例

默认情况下,Red Hat OpenShift GitOps 在 openshift-gitops 命名空间中安装 Argo CD 实例,并使用额外的权限来管理某些集群范围的资源。此默认 Argo CD 实例也称为默认的集群范围的实例。

要防止默认 Argo CD 实例在 openshift-gitops 命名空间中启动,您可以使用 openshift-gitops-operator 订阅并配置 DISABLE_DEFAULT_ARGOCD_INSTANCE 环境变量,将字符串值设置为 "true "。

注意

对于 GitOps 版本 1.13 及之后的版本:

  • 路由 TLS 终止设置为默认和用户定义的 Argo CD 实例的重新加密模式。现在,到 Argo CD 实例的 TLS 连接会收到 OpenShift Container Platform 中设置的默认入口证书,而不是自签名 Argo CD 证书。您可以通过配置 Argo CD CR 的 .spec.server.route.tls 字段来修改路由 TLS 终止策略。
  • 受限 pod 安全准入(PSA)标签应用到 openshift-gitops 命名空间,以确保符合 OpenShift Container Platform 标准。如果您在此命名空间中运行额外的工作负载,如监控或日志记录,请确保它们符合受限的 PSA 要求。如果合规不可用,请考虑使用用户定义的、集群范围的 Argo CD 实例,其中 PSA 标签不会被 GitOps Operator 应用或控制。

要管理集群配置或部署应用程序,您可以安装和部署新的用户定义的 Argo CD 实例。默认情况下,任何新的用户定义实例都只能管理部署它的命名空间中的资源。

您可以在任何命名空间中创建用户定义的 Argo CD 实例,而不是 openshift-gitops 命名空间。

重要

如果要在 openshift-gitops 命名空间中创建用户定义的 Argo CD 实例,请将 openshift-gitops - operator 订阅中的 DISABLE_DEFAULT_ARGOCD_INSTANCE 标志值设置为 "true",且不将实例命名为 openshift-gitops

1.1. 安装用户定义的 Argo CD 实例

要管理集群配置或部署应用程序,您可以安装和部署新的用户定义的 Argo CD 实例。

先决条件

  • 您可以使用 cluster-admin 权限访问集群。
  • 您已在 OpenShift Container Platform 集群上安装了 Red Hat OpenShift GitOps Operator。

流程

  1. 登陆到 OpenShift Container Platform Web 控制台。
  2. 在 Web 控制台的 Administrator 视角中,点 OperatorsInstalled Operators
  3. Project 列表创建或选择您要安装用户定义的 Argo CD 实例的项目。
  4. 从安装的 Operator 列表中选择 Red Hat OpenShift GitOps,然后点击 Argo CD 选项卡。
  5. Create ArgoCD 配置参数:

    1. 输入实例的 Name。默认情况下,Name 设置为 示例
    2. 创建外部操作系统路由来访问 Argo CD 服务器。点 ServerRoute 并检查 Enabled

      提示

      您还可以将 YAML 配置为创建外部操作系统路由,如下例所示:

      已创建外部操作系统路由的 Argo CD 示例

      apiVersion: argoproj.io/v1beta1
      kind: ArgoCD
      metadata:
        name: example
        namespace: openshift-gitops
      spec:
        server:
          route:
            enabled: true
      Copy to Clipboard Toggle word wrap

    3. 可选:通过配置 Argo CD CR 的 .spec.server.route.tls 字段来修改路由 TLS 终止策略。
  6. Create
  7. 进入安装用户定义的 Argo CD 实例的项目中的 NetworkingRoutes → < instance_name>-server
  8. Details 标签页中,点 Route detailsLocation 下的 Argo CD web UI 链接。Argo CD Web UI 在一个单独的浏览器窗口中打开。
  9. 可选: 要使用 OpenShift Container Platform 凭证登录,请确保您是 cluster-admins 组的用户,然后在 Argo CD 用户界面中选择 LOG IN VIA OPENSHIFT 选项。

    注意

    要是 cluster-admins 组的用户,请使用 oc adm groups new cluster-admins <user& gt; 命令,其中 < user > 是您可以在集群范围或本地绑定到用户和组的默认集群角色。

  10. 获取用户定义的 Argo CD 实例的密码:

    1. 使用导航面板进入 WorkloadsSecrets 页面。
    2. 使用 Project 列表,选择创建用户定义的 Argo CD 实例的命名空间。
    3. 选择 & lt;argo_CD_instance_name>-cluster 实例来显示密码。
    4. Details 标签页中,将密码复制到 Dataadmin.password 下。
  11. 使用 admin 作为 Username,复制的密码作为 Password,在新窗口中登录到 Argo CD UI。

作为集群管理员,当您使用 argocd.argoproj.io/managed-by 标签为命名空间提供 Argo CD 访问权限时,Argo CD 会假定 namespace-admin 权限。然后,Red Hat OpenShift GitOps Operator 会自动为以下 GitOps control plane 组件的所有受管命名空间创建角色绑定:

  • Argo CD Application Controller
  • Argo CD 服务器
  • Argo CD ApplicationSet Controller

当您向非管理员用户提供命名空间时,如开发团队,他们可以使用 namespace-admin 特权来修改网络策略等对象。在这些命名空间中安装 Argo CD 实例可让开发团队具有 admin 权限,并间接提升其分配的权限。这些角色具有高度特权,可以删除所有资源。作为防止操作,您可以通过为 Operator 为 Argo CD Application Controller 和 Argo CD 服务器组件创建的所有受管命名空间配置通用集群角色来定义一组特定权限来满足您的安全要求。

要为所有受管命名空间配置通用集群角色,您可以在 Operator 的 Subscription 对象 YAML 文件中为 CONTROLLER_CLUSTER_ROLESERVER_CLUSTER_ROLE 环境变量指定用户定义的集群角色。因此,Operator 会使用现有的用户定义的集群角色,并为所有受管命名空间创建角色绑定,而不是创建默认的 admin 角色。

先决条件

  • 以管理员身份登录到 OpenShift Container Platform 集群。
  • 您已在 OpenShift Container Platform 集群上安装了 Red Hat OpenShift GitOps Operator。

流程

  1. Administrator 视角中,进入到 AdministrationCustomResourceDefinitions
  2. 找到 Subscription CRD 并点它打开它。
  3. 选择 Instances 选项卡,然后点 openshift-gitops-operator 订阅。
  4. 选择 YAML 选项卡并进行自定义:

    • CONTROLLER_CLUSTER_ROLESERVER_CLUSTER_ROLE 环境变量指定用户定义的集群角色:

      订阅示例

      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: openshift-gitops-operator
        namespace: openshift-gitops-operator
      spec:
        config:
          env:
          - name: CONTROLLER_CLUSTER_ROLE
            value: gitops-controller-role 
      1
      
          - name: SERVER_CLUSTER_ROLE
            value: gitops-server-role 
      2
      Copy to Clipboard Toggle word wrap

      1
      Argo CD Application Controller 组件的环境变量名称。
      2
      Argo CD 服务器组件的环境变量名称。
提示

另外,您可以直接将前面的环境变量注入 Operator 的 Deployment 对象 YAML 文件中。

1.3. 为 Argo CD 服务器和存储库服务器启用副本

Argo CD-server 和 Argo CD-repo-server 工作负载是无状态的。要在 pod 中更好地分布工作负载,您可以增加 Argo CD-server 和 Argo CD-repo-server 副本的数量。但是,如果 Argo CD-server 上启用了 pod 横向自动扩展,它会覆盖您设置的副本数。

流程

  • reposerver spec 的 replicas 参数设置为您要运行的副本数:

    Argo CD 自定义资源示例

    apiVersion: argoproj.io/v1beta1
    kind: ArgoCD
    metadata:
      name: example-argocd
      labels:
        example: repo
    spec:
      repo:
        replicas: <number_of_replicas>
      server:
        replicas: <number_of_replicas>
        route:
          enabled: true
          path: /
          tls:
            insecureEdgeTerminationPolicy: Redirect
            termination: passthrough
          wildcardPolicy: None
    Copy to Clipboard Toggle word wrap

1.4. 将资源部署到不同的命名空间中

要允许 Argo CD 管理除安装它外的其他命名空间中的资源,请使用 argocd.argoproj.io/managed-by 标签配置目标命名空间。

流程

  • 运行以下命令来配置目标命名空间:

    $ oc label namespace <target_namespace> \
    argocd.argoproj.io/managed-by=<argocd_namespace>
    Copy to Clipboard Toggle word wrap

    其中:

    <target_namespace>
    指定您要管理 Argo CD 的命名空间的名称。
    <argocd_namespace>
    指定安装 Argo CD 的命名空间的名称。

第 2 章 Argo CD 自定义资源和组件属性

ArgoCD 自定义资源(CRD)是一个 Kubernetes 自定义资源(CRD),用于描述给定 Argo CD 集群的所需状态,允许您配置组成 Argo CD 集群的组件。

2.1. Argo CD 自定义资源属性

Argo CD 自定义资源由以下属性组成:

Expand
Name描述defaultProperties

aggregatedClusterRoles

为集群范围的实例的 Argo CD Application Controller 组件使用聚合的集群角色。

false

 

applicationInstanceLabelKey

Argo CD 注入应用程序名称的 metadata.label 键名称作为一个跟踪标签。

app.kubernetes.io/instance

 

applicationSet

ApplicationSet Controller 配置选项。

object

  • enabled - 在 Argo CD 安装过程中用来启用 ApplicationSet Controller 的标志。
  • env - 指定 ApplicationSet Controller pod 的环境。
  • extraCommandArgs - 列表添加到 Operator 为 ApplicationSet 工作负载设置的现有参数中。
  • image - ApplicationSet Controller 的容器镜像。此属性覆盖 ARGOCD_APPLICATIONSET_IMAGE 环境变量。
  • loglevel - Argo CD Application Controller 组件使用的日志级别。有效选项包括 debuginfoerrorwarn
  • logFormat - Argo CD Application Controller 组件使用的日志格式。有效选项为 textjson
  • parallelismLimit - 为控制器设置的 kubectl parallelism 限制( --kubectl-parallelism-limit 标志)。
  • resources - 容器计算资源。
  • scmProviders - 允许的源代码管理器(SCM)供应商的 URL。
  • scmRootCAConfigMap - 存储 Gitlab SCM 提供程序 TLS 证书的配置映射的名称,该证书将被挂载到"/app/tls/scm/cert"路径的 Application Set Controller 上。
  • sourceNamespaces - 在目标命名空间中创建和管理 Argo CD ApplicationSet 资源的非 control plane 命名空间列表。
  • version - 与 applicationSet 容器镜像一起使用的标签。
  • Argo CD ApplicationSet Controller 组件配置的添加卷的卷列表。此字段是可选的。
  • volumeMounts - 添加为 Argo CD ApplicationSet Controller 组件配置的卷挂载列表。此字段是可选的。
  • webhook server- 定义 ApplicationSet webhook 服务器的可用选项。

banner

添加 UI 横幅消息。

object

  • banner.content - 横幅消息内容。如果显示横幅,则需要此内容。
  • banner.url - 可选横幅消息链接 URL。

configManagementPlugins

添加配置管理插件。

empty

 

controller

Argo CD Application Controller 选项。

object

  • AppSync- AppSync 用于控制 Argo CD 应用程序的同步频率。
  • 应用程序控制器工作负载设置的环境。
  • extraCommandArgs - list 添加至 Operator 设置的现有参数中。
  • initContainers - ArgoCD 应用程序控制器组件的 init 容器列表。此字段是可选的。
  • loglevel - Argo CD Application Controller 组件使用的日志级别。有效选项包括 debuginfoerrorwarn
  • Processor.operation - 操作处理器的数量。
  • processor.status - 状态处理器的数量。
  • resources - 容器计算资源。
  • sidecarContainers - ArgoCD Application Controller 组件的 sidecar 容器列表。此字段是可选的。
  • 在 Argo CD Application Controller 组件中 分片.enabled - 启用分片。使用此属性管理大量集群,并缓解控制器组件的内存压力。
  • sharding.replicas - 用于支持 Argo CD Application Controller 分片的副本数。
  • sharding.dynamicScalingEnabled - 启用 Argo CD Application Controller 组件的动态扩展。如果您希望 Operator 根据控制器组件管理的集群数量扩展副本数,请使用此属性。如果将此属性设置为 true,它会覆盖 sharding. enabled 和 sharding.replicas 属性的配置。
  • sharding.minShards - Argo CD Application Controller 副本的最小数量。
  • sharding.maxShards - Argo CD Application Controller 副本的最大数量。
  • sharding.clustersPerShard - 需要由每个分片管理的集群数量。当副本数达到 maxShards 时,分片会管理多个集群。
  • 为 Argo CD Application Controller 组件配置的卷添加 卷列表。此字段是可选的。
  • volumeMounts - 添加为 Argo CD Application Controller 组件配置的卷挂载列表。此字段是可选的。

disableAdmin

禁用内置的 admin 用户。

false

 

defaultClusterScopedRoleDisabled

禁用为集群范围的实例创建默认集群角色。

false

 

extraConfig

将任何补充 Argo CD 设置添加到 argocd-cm 配置映射中,这些配置映射不能直接在 Argo CD 自定义资源中配置。

empty

 

gaTrackingID

使用 Google Analytics 跟踪 ID。

empty

 

gaAnonymizeUsers

启用发送到 Google Analytics 的散列用户名。

false

 

ha

高可用性选项。

object

  • 启用 - 为 Argo CD 切换全局的高可用性支持。
  • redisProxyImage - Redis HAProxy 容器镜像。此属性覆盖 ARGOCD_REDIS_HA_PROXY_IMAGE 环境变量。
  • redisProxyVersion - 用于 Redis HAProxy 容器镜像的标签。

helpChatURL

用于获取聊天帮助的 URL (通常是您的 Slack 频道支持)。

https://mycorp.slack.com/argo-cd

 

helpChatText

显示在进行聊天帮助的文本框中。

现在聊天!

 

image

所有 Argo CD 组件的容器镜像。这会覆盖 ARGOCD_IMAGE 环境变量。

argoproj/argocd

 

import

为 Argo CD 导入配置选项。

object

  • name - 可以从中导入数据的 ArgoCDExport 资源的名称。
  • namespace - 由 name 字段引用的 ArgoCDExport 资源的命名空间。如果没有设置此字段,则 ArgoCDExport 资源的命名空间默认设置为与 Argo CD 相同的命名空间。

ingress

Ingress 配置选项。

object

 

initialRepositories

初始 Git 存储库,将 Argo CD 配置为在创建集群时使用。

empty

 

initialSSHKnownHosts

定义 Argo CD 的初始 SSH 已知主机数据,以便在集群创建时使用,以通过 SSH 连接到 Git 存储库。

default_Argo_CD_Known_Hosts

  • excludedefaulthosts - 表示您要添加 Argo CD 提供的 SSH 已知问题的默认列表。
  • keys - 描述您要合并到 Argo CD 服务器的一组自定义 SSH 已知问题。

kustomizeBuildOptions

用于 kustomize build 的构建选项和参数。

empty

 

kustomizeVersions

定义在 Argo CD 仓库服务器容器镜像中配置的 Kustomize 版本列表。

empty

  • path - Argo CD repo 服务器容器镜像的文件系统中的 Kustomize 版本路径。
  • version - 在 Argo CD repo 服务器容器镜像中配置的 vX.Y.Z 格式的 Kustomize 版本。

monitoring

为您的实例定义工作负载状态监控配置。

object

  • disableMetrics - Configure this 字段,以启用或禁用您的实例的指标集合。
  • enabled - 指示是否为您的实例启用工作负载状态监控。

notifications

通知控制器配置选项。

object

  • enabled - 切换启动通知控制器。
  • env - 为通知控制器工作负载设置的环境。
  • image - 所有 Argo CD 组件的容器镜像。此属性覆盖 ARGOCD_IMAGE 环境变量。
  • loglevel - Argo CD Application Controller 组件使用的日志级别。有效选项包括 debuginfoerrorwarn
  • replicas - 为 Notifications 控制器运行的副本数。
  • resources - 容器计算资源。
  • version - 与 Notifications 容器镜像一起使用的标签。

nodePlacement

为 Argo CD 工作负载定义 NodeSelectorsTolerations

empty

  • nodeSelector - 节点选择的键值对映射。
  • tolerations -Tolerations 允许 pod 为具有匹配污点的节点创建调度。

oidcConfig

OIDC 配置作为 Dex 的替代方案。

empty

 

prometheus

Prometheus 配置选项。

object

  • 启用 - 为 Argo CD 切换全局的 Prometheus 支持。
  • Host - 用于 IngressRoute 资源的主机名。
  • Prometheus 的 Ingress 切换入口。
  • Route - Route 配置选项。
  • size - Prometheus StatefulSet 的副本数。

rbac

RBAC 配置选项。

object

  • defaultPolicy - argocd-rbac-cm 配置映射中的 policy.default 属性。Argo CD 在授权 API 请求时回退到的默认角色的名称。
  • policy -rbac- rbac-cm 配置映射中的 policy.csv 属性。此属性包含有关用户定义的 RBAC 策略和角色定义的 CSV 数据。
  • policyMatcher - argocd-rbac-cm 配置映射中的 policy.matchMode 属性。此属性有两个选项:'glob' for glob matcher 和 'regex' 用于 regex matcher。
  • scopes - argocd-rbac-cm 配置映射中的 scopes 属性。除了子范围外,控制在 RBAC 执行期间要检查的 OIDC 范围。

redis

Redis 配置选项。

object

  • autotls - 使用供应商创建 Redis 服务器的 TLS 证书。当前只有 openshift 值可用。
  • disableTLSVerification - 定义是否应使用严格的 TLS 验证访问 Redis 服务器。
  • image - Redis 的容器镜像。这会覆盖 ARGOCD_REDIS_IMAGE 环境变量。
  • resources - 容器计算资源。
  • version - 与 Redis 容器镜像一起使用的标签。

repositoryCredentials

Git 存储库凭证模板,将 Argo CD 配置为在集群创建时使用。

empty

 

resourceActions

自定义资源操作行为。

empty

 

resourceExclusions

完全忽略整个资源组类别。

empty

 

resourceInclusions

用于标识要应用哪些资源组/kinds 的配置。

empty

 

resourceHealthChecks

自定义资源健康检查行为。

empty

 

resourceIgnoreDifferences

自定义资源忽略差异行为。

empty

 

resourceTrackingMethod

Argo CD 用来监控其受管资源的字段。

label

 

server

Argo CD Server 配置选项。

object

  • autoscale - Server autoscale 配置选项。
  • 为服务器工作负载设置的环境。
  • enabled - 在 Argo CD 安装过程中启用 Argo CD 服务器的标志。
  • enableRolloutsUI - 当参数设置为 true 时,该参数会在 Argo CD 中启用 Argo Rollouts UI 扩展。默认值为 false
  • extraCommandArgs - list 添加至 Operator 设置的现有参数中。
  • gRPC - gRPC 配置选项。
  • host - 用于 IngressRoute 资源的主机名。
  • initContainers - Argo CD Application Controller 组件的 init 容器列表。此字段是可选的。
  • Argo CD 服务器组件的 Ingress 配置。
  • insecure - 切换 Argo CD 服务器的 insecure 标志。
  • Loglevel - Argo CD 服务器组件使用的日志级别。有效选项包括 debuginfoerrorwarn
  • logFormat - Argo CD 服务器组件使用的日志格式。有效选项为 textjson
  • resources - 容器计算资源。
  • replicas - Argo CD 服务器的副本数量。必须大于或等于 0。如果启用了 自动扩展,则忽略 副本
  • Route - Route 配置选项。
  • service.Type - 用于服务资源的 serviceType
  • sidecarContainers - Argo CD Application Controller 组件的 sidecar 容器列表。此字段是可选的。
  • 为 Argo CD Application Controller 组件配置的卷添加 卷列表。此字段是可选的。
  • volumeMounts - 添加为 Argo CD Application Controller 组件配置的卷挂载列表。此字段是可选的。

sourceNamespaces

指定在其中创建应用程序资源的命名空间。

string

 

sso

单点登录选项。

object

  • Dex SSO 提供程序的 Dex 配置选项。
  • Keycloak SSO 提供程序的 Keycloak 配置选项。
  • provider - configuration Single Sign-on 的提供程序名称。目前,支持的选项有 Dex 和 Keycloak。

statusBadgeEnabled

启用应用程序状态徽标。

true

 

tls

TLS 配置选项。

object

  • ca.configMapName - 包含 CA 证书的 ConfigMap 名称。
  • ca.secretName - 包含 CA 证书和密钥的 secret 名称。
  • initialCerts - Initial set in the argocd-tls-certs-cm 配置映射中,用于通过 HTTPS 连接 Git 存储库。

usersAnonymousEnabled

启用匿名用户访问。

true

 

version

用于所有 Argo CD 组件的容器镜像的标签。

 

最新的 Argo CD 版本

2.2. 仓库服务器属性

以下属性可用于配置存储库服务器组件:

Expand
Namedefault描述

autotls

""

用于为 repo-server 的 gRPC TLS 证书设置 TLS 的供应商。目前,只有 openshift 值可以接受。

env

empty

为 Repo 服务器工作负载设置的环境。

enabled

empty

在 Argo CD 安装过程中启用 Repo 服务器的标记。

execTimeout

180

渲染工具(如 Helm 或 Kustomize)的执行超时(以秒为单位)。

extraRepoCommandArgs

empty

将命令行参数传递给 Repo 服务器工作负载。命令行参数添加到 Operator 设置的参数列表中。

initContainers

empty

Argo CD Application Controller 组件中的 init 容器数量。此字段是可选的。

image

argoproj/argocd

Argo CD Repo 服务器的容器镜像。这个正确的覆盖了 ARGOCD_REPOSERVER_IMAGE 环境变量。

logLevel

info

Argo CD Repo 服务器使用的日志级别。有效选项包括 debuginfoerrorwarn

logFormat

text

Argo CD repo 服务器使用的日志格式。有效选项为 textjson

mountatoken

false

定义 serviceaccount 令牌是否应挂载到 repo-server pod。

remote

empty

指定 Repo 服务器容器的远程 URL。

replicas

empty

Argo CD Repo 服务器的副本数。必须大于或等于 0

resources

empty

容器计算资源。

serviceaccount

""

与 repo-server pod 搭配使用的 serviceaccount 的名称。

sidecarContainers

empty

Argo CD Application Controller 组件中的 sidecar 容器数量。此字段是可选的。

verifytls

false

定义在与存储库服务器通信时,是否在所有组件上执行严格的 TLS 检查。

version

.spec.Version 相同

与 Argo CD Repo 服务器一起使用的标签。

empty

配置用于 Repo 服务器部署的额外卷。此字段是可选的。

volumeMounts

empty

配置用于 Repo 服务器部署的额外卷挂载。此字段是可选的。

2.3. 使用 Argo CD 实例启用通知

Argo CD 通知允许您在 Argo CD 实例中发生事件时向外部服务发送通知。例如,您可以在同步操作失败时向 Slack 或发送电子邮件发送通知。默认情况下,在 Argo CD 实例中禁用通知。

先决条件

  • 您可以使用 cluster-admin 权限访问 OpenShift Container Platform 集群,并登录到 web 控制台。
  • 在集群中安装了 Red Hat OpenShift GitOps Operator。

流程

要使用 OpenShift Container Platform Web 控制台为 Argo CD 实例启用通知,请完成以下步骤:

  1. 导航到 OperatorsInstalled Operators 页面。
  2. Installed Operators 列表中,选择 Red Hat OpenShift GitOps Operator,然后点 ArgoCD 选项卡。
  3. 选择您要启用通知的 Argo CD 实例名称。例如,openshift-gitops
  4. YAML 选项卡,然后编辑 spec.notifications.enabled 参数设置为 true

    Example

    apiVersion: argoproj.io/v1beta1
    kind: ArgoCD
    metadata:
      name: openshift-gitops
    spec:
      notifications:
        enabled: true
    #....
    Copy to Clipboard Toggle word wrap

  5. 点击 Save
提示

或者,您可以使用 Openshift CLI 中的 oc patch 命令启用通知。例如:

oc patch argocd openshift-gitops -n openshift-gitops --type merge --patch '{"spec": {"notifications": {"enabled": true}}}'
Copy to Clipboard Toggle word wrap

2.4. NotificationsConfiguration 自定义资源属性

NotificationsConfiguration 资源是一个 Kubernetes 自定义资源(CR),用于管理 Kubernetes 集群中的通知。在 Red Hat OpenShift GitOps 中,您可以使用 Notifications Configuration CR 将模板、触发器、服务和订阅资源添加到 Argo CD 通知配置映射中。

当您在启用了通知的 Red Hat OpenShift GitOps 中创建集群时,默认会创建一个带有名称 default-notifications-configurationNotificationsConfiguration CR。

NotificationsConfiguration CR 的现有配置中所做的任何更改都会在 Argo CD 通知 配置映射中复制。例如,如果用户在 NotificationsConfiguration 资源中添加触发器配置,则此配置会在 Argo CD Notifications 配置映射中读取、处理和更新。

重要

任何配置更改都必须在 default-notifications-configuration CR 中更新。不支持为 NotificationsConfiguration 资源用户创建的自定义资源。

对 Argo CD argocd-notifications-cm 配置映射的任何修改都会被 NotificationsConfiguration CR 中所做的更改覆盖。

Expand
表 2.1. NotificationsConfiguration 自定义资源属性
Propertiesdefault描述

模板

<empty>

模板用于生成通知模板消息。

触发器

<empty>

触发器用于定义在向用户以及生成消息所需的模板列表通知时的条件。

服务

<empty>

服务用于发送消息。

订阅

<empty>

订阅包含集中管理的全局应用程序订阅。

以下示例定义如何使用 default-notifications-configuration 自定义资源将模板、触发器、服务和订阅资源添加到 Argo CD argocd-notification-cm 配置映射。

模板示例

apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
 name: default-notifications-configuration 
1

spec:
 templates:
  template.my-custom-template: | 
2

    message: |
     Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
Copy to Clipboard Toggle word wrap

1
集群中的 NotificationsConfiguration CR 的默认名称。
2
NotificationsConfiguration CR 的自定义模板配置示例。

触发器示例

apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
 name: default-notifications-configuration 
1

spec:
 triggers:
  trigger.on-sync-status-unknown: | 
2

   - when: app.status.sync.status == 'Unknown'
   send: [my-custom-template]
Copy to Clipboard Toggle word wrap

1
集群中的 NotificationsConfiguration CR 的默认名称。
2
NotificationsConfiguration CR 的自定义触发器配置示例。

服务示例

apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
 name: default-notifications-configuration 
1

spec:
 Services:
  service.slack: |
    token: $slack-token 
2

    username: <override-username> # optional username
    icon: <override-icon> # optional icon for the message (supports both emoji and url notation)
Copy to Clipboard Toggle word wrap

1
集群中的 NotificationsConfiguration CR 的默认名称。
2
NotificationsConfiguration CR 的自定义服务配置示例。

订阅示例

apiVersion: argoproj.io/v1alpha1
kind: NotificationsConfiguration
metadata:
 name: default-notifications-configuration 
1

spec:
 Subscriptions: |
  subscriptions: | 
2

    # subscription for on-sync-status-unknown trigger notifications
    - recipients:
    - slack:test2
    - email:test@gmail.com
    triggers:
    - on-sync-status-unknown
    # subscription restricted to applications with matching labels only
    - recipients:
    - slack:test3
    selector: test=true
    triggers:
    - on-sync-status-unknown
icon: <override-icon> # optional icon for the message (supports both emoji and url notation)
Copy to Clipboard Toggle word wrap

1
集群中的 NotificationsConfiguration CR 的默认名称。
2
NotificationsConfiguration CR 的自定义订阅配置示例。

您可以使用 OpenShift Container Platform Web 控制台或 CLI (oc)配置 NotificationsConfiguration CR。

您可以使用 Web 控制台配置 NotificationsConfiguration 自定义资源(CR)。

先决条件

  • 您可以使用 cluster-admin 权限访问 OpenShift Container Platform 集群,并登录到 web 控制台。
  • 在集群中安装了 Red Hat OpenShift GitOps Operator。
  • 您已为 Argo CD 实例启用了通知。如需更多信息,请参阅"使用 Argo CD 实例启用通知"。

流程

  1. 在 OpenShift Container Platform Web 控制台的 Administrator 视角中,展开 OperatorsInstalled Operators
  2. Installed Operators 列表中,选择 Red Hat OpenShift GitOps Operator,然后点 NotificationsConfiguration 选项卡。
  3. NotificationsConfigurations 页面中,单击 default-notifications-configuration
  4. default-notifications-configuration 页面中,单击 YAML 并添加任何受支持的资源的配置,如 模板触发器服务 和订阅。例如,在代码中的模板 下,添加以下示例配置:

    模板配置示例

      template.my-custom-template: |
        message: |
        Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
    Copy to Clipboard Toggle word wrap

  5. 点击 Save
  6. 验证 NotificationsConfiguration CR 中进行的配置更改是否已反映在 argocd-notifications-cm 配置映射中:

    1. 进入 WorkloadsConfigMaps
    2. argocd-notifications-cm 并选择 YAML 选项卡。
    3. 滚动浏览 YAML 选项卡中的页面,以验证为支持的资源添加的示例配置。

2.4.2. 使用 CLI 配置 NotificationsConfiguration CR

您可以使用 CLI (oc)配置 NotificationsConfiguration 自定义资源(CR)。

先决条件

  • 您可以使用 cluster-admin 权限访问 OpenShift Container Platform 集群。
  • 在集群中安装了 Red Hat OpenShift GitOps Operator。
  • 您已为 Argo CD 实例启用了通知。如需更多信息,请参阅"使用 Argo CD 实例启用通知"。

流程

  1. 运行以下命令来编辑集群中的默认 NotificationsConfiguration CR:

    $ oc edit notificationsconfiguration default-notifications-configuration -n <namespace>
    Copy to Clipboard Toggle word wrap

    其中:

    default-notifications-configuration
    指定默认 NotificationsConfiguration CR 的名称。
    <namespace>
    指定命名空间的名称。
  2. 在 CR 的 templates 部分,添加类似以下示例的配置:

    模板配置示例

      template.my-custom-template: |
        message: |
        Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
    Copy to Clipboard Toggle word wrap

  3. 运行以下命令,验证 argocd-notifications-cm 配置映射的内容:

    $ oc edit cm argocd-notifications-cm -n <namespace>
    Copy to Clipboard Toggle word wrap

    NotificationsConfiguration CR 的现有配置中所做的更改反映在 argocd-notifications-cm 配置映射中。

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat