Backstage 的 ArgoCD 插件


Red Hat Developer Hub 0.2

Backstage 的 ArgoCD 插件

Red Hat Customer Content Services

摘要

ArgoCD 插件代表应用程序的当前状态。

第 1 章 Backstage 的 ArgoCD 插件

ArgoCD 插件代表 Backstage Catalog 中应用程序的当前状态。

1.1. 对于管理员

1.1.1. 安装

用于 Backstage (RHPIB)软件包的红帽插件托管在单独的 NPM registry 中,由红帽维护。要使用这些软件包,您必须调整 NPM 配置来拉取 @redhat 有范围的软件包:

# update your .npmrc or .yarnrc file
yarn config set "@redhat:registry" https://npm.registry.redhat.com
# then pull a package
yarn add @redhat/backstage-plugin-quay

如需更多信息,请参阅 npm 文档

创建 .npmrc 文件可确保所有软件包都限定在 @redhat 下,并从 红帽的 NPM registry 获取,而其余依赖项仍来自其他 registry

前提条件

  • 您的 Backstage 应用程序已安装并部署。

流程

  1. backstage/packages/app 项目中,将 ArgoCD 插件添加为 package.json 依赖项,如下所示:

    cd packages/app
    yarn add @redhat/backstage-plugin-argo-cd
  2. 在根目录中的 app-config.yaml 文件中,将 argo-cd 添加到 proxy 对象中,如下所示:

    proxy:
      ...
    
      '/argocd/api':
        # url to the api of your hosted argoCD instance
        target: https://159.65.209.132/api/v1/
        changeOrigin: true
        # this line is required if your hosted argoCD instance has self-signed certificate
        secure: false
        headers:
          Cookie:
            $env: ARGOCD_AUTH_TOKEN
    
    
    # optional: this will link to your argoCD web UI for each argoCD application
    argocd:
      baseUrl: https://my-argocd-web-ui.com

    另外,您还可以在前面的代码中为 ArgoCD Web UI 添加基本 URL。

  3. 使用以下代码将 ArgoCD 插件添加到插件列表中:

    // packages/app/src/plugins.ts
    export { argocdPlugin } from '@redhat/backstage-plugin-argo-cd';
  4. 将 ArgoCD 插件添加到 ENT itityPage.tsx 文件中,如下所示:

    // packages/app/src/components/catalog/EntityPage.tsx
    import {
      EntityArgoCDHistoryCard,
      isArgocdAvailable,
    } from '@redhat/backstage-plugin-argo-cd';
    
    
    const overviewContent = (
      <Grid container spacing={3} alignItems="stretch">
        ...
        <EntitySwitch>
          <EntitySwitch.Case if={e => Boolean(isArgocdAvailable(e))}>
            <Grid item sm={6}>
              <EntityArgoCDHistoryCard />
            </Grid>
          </EntitySwitch.Case>
        </EntitySwitch>
        ...
      </Grid>
    );
  5. 要在 Backstage 中为组件使用 ArgoCD 插件,请在组件的 YAML 配置文件中添加注解:

    argocd/app-name: <app-name>

    要为组件选择多个 ArgoCD 应用程序,请使用标签,如下所示:

    argocd/app-selector: <app-selector>

    注意

    您可以对组件使用注解或标签。

  6. 使用用户名和密码向 ArgoCD 的 /session 端点发送 GET HTTP 请求,以获取您的身份验证密钥。
  7. 将获取的身份验证密钥添加到 Backstage 后端服务器的环境变量中,如下所示:

    ARGOCD_AUTH_TOKEN="argocd.token=<auth-token>"

1.2. 支持 backstage 中的多个 ArgoCD 实例

在 Backstage 中支持多个 ArgoCD 实例有两个选项,包括:

  • 为每个 ArgoCD 实例添加代理配置
  • 使用 ArgoCD 后端插件

选项 1:为每个 ArgoCD 实例添加代理配置

  1. 要创建从不同 ArgoCD 实例获取数据的多个组件,请为每个实例添加代理配置,如下例所示:

    proxy:
      ...
    
      '/argocd/api':
        target: https://<someAddress>/api/v1/
        changeOrigin: true
        secure: false
        headers:
          Cookie:
            $env: ARGOCD_AUTH_TOKEN
    
      '/argocd/api2':
        target: https://<otherAddress>/api/v1/
        changeOrigin: true
        secure: false
        headers:
          Cookie:
            $env: ARGOCD_AUTH_TOKEN2
  2. 将所需的身份验证令牌添加到环境变量中,如 ARGOCD_AUTH_TOKEN2

    添加身份验证令牌后,将 URL 添加到以下组件定义注解中的所需代理路径中:

    argocd/proxy-url: '/argocd/api2'

    argocd/proxy-url 注解默认为 '/argocd/api'。因此,如果存在单一代理配置,则不需要 argocd/proxy-url

选项 2:使用 ArgoCD 后端插件

  1. 要创建从不同 ArgoCD 实例获取数据的多个组件,请通过将以下配置添加到 app-config.yaml 文件中来动态设置 ArgoCD 实例 URL:

    argocd:
      username: ${ARGOCD_USERNAME}
      password: ${ARGOCD_PASSWORD}
      waitCycles: 25
      appLocatorMethods:
        - type: 'config'
          instances:
            - name: argoInstance1
              url: https://argoInstance1.com
              token: ${ARGOCD_AUTH_TOKEN} # optional
            - name: argoInstance2
              url: https://argoInstance2.com
              # dedicated username/password for this instance
              username: ${ARGOCD_USERNAME_INSTANCE_2} # optional
              password: ${ARGOCD_PASSWORD_INSTANCE_2} # optional

    在删除 ArgoCD 项目和应用程序之间创建一个循环,以检查删除项目前发生的应用程序。如果 waitCycles 设为 25,则循环在出错前可能持续 75 秒。

    使用前面的配置,ArgoCD 插件获取应用程序要部署到的 ArgoCD 实例,并使用 ArgoCD 后端插件(backstage-plugin-argo-cd-backend)来根据以下映射访问每个 ArgoCD 实例:

    • 将所需的身份验证令牌添加到环境变量中,如 argocd 对象中的 ARGOCD_USERNAMEARGOCD_PASSWORD。这些身份验证令牌默认用作所有 ArgoCD 实例的凭证。

      argocd:
        username: ${ARGOCD_USERNAME}
        password: ${ARGOCD_PASSWORD}
        appLocatorMethods:
          - type: 'config'
            instances:
              - name: argoInstance1
                url: https://argoInstance1.com
              - name: argoInstance2
                url: https://argoInstance2.com
    • 为每个 ArgoCD 实例定义一个用户名和密码。这个映射的优先级高于上一个选项。

      argocd:
        username: ${ARGOCD_USERNAME}
        password: ${ARGOCD_PASSWORD}
        appLocatorMethods:
          - type: 'config'
            instances:
              - name: argoInstance1
                url: https://argoInstance1.com
              - name: argoInstance2
                url: https://argoInstance2.com
                # dedicated username/password for this instance
                username: ${ARGOCD_USERNAME_INSTANCE_2}
                password: ${ARGOCD_PASSWORD_INSTANCE_2}
    • 为每个实例定义令牌。这个映射的优先级高于前面提到的两个选项。

      argocd:
        username: ${ARGOCD_USERNAME}
        password: ${ARGOCD_PASSWORD}
        appLocatorMethods:
          - type: 'config'
            instances:
              - name: argoInstance1
                url: https://argoInstance1.com
                token: ${ARGOCD_AUTH_TOKEN} # Token to use to instance 1

1.2.1. ArgoCD 插件中的权限

为 ArgoCD 用户帐户设置权限不仅降低了范围,还减少了后端的功能。如果您限制了只读权限,则包括创建、删除和重新同步应用程序的操作将不可用。

ArgoCD 中的错误处理旨在提醒您何时没有正确的权限。

1.2.2. ArgoCD 插件中的自签名证书

默认情况下,ArgoCD 服务器生成自签名证书。安装 ArgoCD 插件后,使用以下命令将 argocd-server 的部署修补为不安全:

kubectl patch deployment argocd-server --type "json" -p '[{"op":"add","path":"/spec/template/spec/containers/0/command/-","value":"--insecure"}]'

另外,您可以使用 Helm 安装 ArgoCD 插件,默认是不安全的:

helm upgrade --install argocd argo/argo-cd \
  --version 3.33.5 \
  --set 'server.extraArgs={--insecure}'

1.3. 对于用户

1.3.1. 在 Backstage 中使用 ArgoCD 插件

ArgoCD 插件在 Backstage Catalog 中显示应用程序的当前状态。

前提条件

  • 您的 Backstage 应用程序已安装并运行。
  • 已安装 ArgoCD 插件。有关安装步骤,请参阅 第 1.1.1 节 “安装”

流程

  1. 打开 Backstage 应用程序,再进入 Catalog 页面。
  2. OVERVIEW 选项卡中,您可以在底部看到 ArgoCD 概述卡。

    ArgoCD 概述卡

    ArgoCD 概述卡显示应用程序信息,包括 NAME,INSTANCE,SYNC STATUS,HEALTH STATUS, 和 LAST SYNCED

  3. 要查看详细的应用程序信息,请从 ArgoCD 概述卡中选择应用程序。

    此时会出现一个包含应用程序详细信息的弹出窗口,以及 ArgoCD 仪表板的链接。

    ArgoCD 概述卡
  4. 要查看 ArgoCD 历史记录,请转至 Catalog 中的 CD 选项卡。

    ArgoCD 概述卡

    ArgoCD 历史记录 页面包含应用程序实例的历史记录以及其他信息,如部署详情、作者名称、作者和修订 ID 的消息。

法律通告

Copyright © 2023 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 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

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

© 2024 Red Hat, Inc.