为 Backstage 打开 Cluster Management 插件


Red Hat Plug-ins for Backstage 1.0

Backstage 的 Open Cluster Management 插件

Red Hat Customer Content Services

摘要

Open Cluster Management (OCM)插件将 Backstage 实例与 OCM 的 'MultiClusterHub' 和 'MultiCluster' 引擎集成。

第 1 章 为 Backstage 打开 Cluster Management 插件

Open Cluster Management (OCM)插件将您的 Backstage 实例与 OCM 的 MultiClusterHubMultiCluster 引擎集成。

1.1. 功能

OCM 插件具有以下功能:

  • MultiClusterHub 或 MCE 中,所有以 ManagedCluster 代表的集群都会被发现并导入到 Backstage 目录中,例如:

    • 实体被定义为 kind: Resource,将 spec.type 设置为 kubernetes-cluster
    • metadata.links 中提供了到 OpenShift Container Platform (OCP)控制台、OCM 控制台和 OpenShift Cluster Manager 的链接。
  • 在 Resource entity 页面中显示 OCM 中的实时数据,包括:

    • 集群当前状态(up 或 down)
    • 集群节点状态(up 或 down)
    • 集群详情(控制台链接、OCP 和 Kubernetes 版本)
    • 有关集群中可用计算资源的详情

1.2. 对于管理员

1.2.1. 安装

用于 Backstage (RHPIB)软件包的红帽插件托管在单独的 NPM registry 中,由红帽维护。要使用 RHPIB NPM 软件包,您必须调整 NPM 配置。您可以创建一个 .npmrc 文件,其中包含以下内容:

@redhat:registry=https://npm.registry.redhat.com/ registry=https://registry.npmjs.org

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

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

使用这个配置,您可以继续安装单个软件包。

OCM 插件由两个软件包组成,包括:

注意

如果您对资源发现感兴趣,且不想使用任何前端组件,那么您只能安装和配置 @redhat/backstage-plugin-ocm-backend 软件包。

1.2.1.1. 先决条件
  • OCM 在 Kubernetes 集群上部署和配置。
  • 已安装 Backstage 的 Kubernetes 插件
  • ClusterRole 被授予 ServiceAccount 访问 hub 集群,如下所示:

      kind: ClusterRole
      apiVersion: rbac.authorization.k8s.io/v1
      metadata:
        name: backstage-ocm-plugin
      rules:
        - apiGroups:
            - cluster.open-cluster-management.io
          resources:
            - managedclusters
          verbs:
            - get
            - watch
            - list
        - apiGroups:
            - internal.open-cluster-management.io
          resources:
            - managedclusterinfos
          verbs:
            - get
            - watch
            - list
1.2.1.2. 设置 OCM 后端软件包
  1. 使用以下命令安装 OCM 后端插件:

    yarn workspace backend add @redhat/backstage-plugin-ocm-backend
  2. 使用以下配置之一配置 OCM 后端插件:

    • OCM 配置提供有关 hub 的信息。要使用 OCM 配置,请在 app-config.yaml 文件中添加以下代码:

      `yaml title="app-config.yaml"
           catalog:
             providers:
               ocm:
                 env: # Key is reflected as provider ID. Defines and claims plugin instance ownership of entities
                   name: # Name that the hub cluster will assume in Backstage Catalog (in OCM this is always local-cluster which can be confusing)
                   url: # Url of the hub cluster API endpoint
                   serviceAccountToken: # Token used for querying data from the hub
                   skipTLSVerify: # Skip TLS certificate verification, defaults to false
                   caData: # Base64-encoded CA bundle in PEM format
    • 如果安装了 Backstage Kubernetes 插件并配置为连接到 hub 集群,则您可以通过在 app-config.yaml 中提供 hub 和 Kubernetes 配置来绑定 hub 和 Kubernetes 配置,如下所示:

      ```yaml title="app-config.yaml"
           kubernetes:
             serviceLocatorMethod:
               type: 'multiTenant'
             clusterLocatorMethods:
               - type: 'config'
                 clusters:
                   # highlight-next-line
                   - name: <cluster-name>
                   # ...
      
           catalog:
             providers:
               ocm:
                 env: # Key is reflected as provider ID. Defines and claims plugin instance ownership of entities
                   # highlight-next-line
                   kubernetesPluginRef: <cluster-name> # Match the cluster name in kubernetes plugin config

      确保 Backstage 使用 ServiceAccount 令牌,并且授予前面所述所需的权限。

      当您已在 Backstage 实例中使用 Kubernetes 插件时,这非常有用。另外,hub 集群必须使用 ServiceAccount 连接。

      如需有关配置的更多信息,请参阅 Backstage Kubernetes 插件 文档。

  3. packages/backend/src/plugins/ocm.ts 文件中创建一个新的插件实例,如下所示:

    ```ts title="packages/backend/src/plugins/ocm.ts"
       import { Router } from 'express';
    
       import { createRouter } from '@redhat/backstage-plugin-ocm-backend';
    
       import { PluginEnvironment } from '../types';
    
       export default async function createPlugin(
         env: PluginEnvironment,
       ): Promise<Router> {
         return await createRouter({
           logger: env.logger,
           config: env.config,
         });
       }
  4. 将新实例导入 packages/backend/src/index.ts 文件中:

    ```ts title="packages/backend/src/index.ts"
       /* highlight-add-next-line */
       import ocm from './plugins/ocm';
    
       async function main() {
         // ...
         const createEnv = makeCreateEnv(config);
         // ...
         /* highlight-add-next-line */
         const ocmEnv = useHotMemoize(module, () => createEnv('ocm'));
         // ...
         const apiRouter = Router();
         // ...
         /* highlight-add-next-line */
         apiRouter.use('/ocm', await ocm(ocmEnv));
         // ...
       }
    ```
  5. packages/backend/src/plugins/ catalog.ts 文件中,将集群资源实体供应商导入到目录源中。还需要配置调度程序。这里有两个配置:

    1. app-config.yaml 中配置调度程序:

      ```yaml title="app-config.yaml"
            catalog:
              providers:
                ocm:
                  env:
                    # ...
                    # highlight-add-start
                    schedule: # optional; same options as in TaskScheduleDefinition
                      # supports cron, ISO duration, "human duration" as used in code
                      frequency: { minutes: 1 }
                      # supports ISO duration, "human duration" as used in code
                      timeout: { minutes: 1 }
                    # highlight-add-end
      +

      然后,使用配置的调度程序

      ```ts title="packages/backend/src/index.ts"
            /* highlight-add-next-line */
            import { ManagedClusterProvider } from '@redhat/backstage-plugin-ocm-backend';
      
            export default async function createPlugin(
              env: PluginEnvironment,
            ): Promise<Router> {
              const builder = await CatalogBuilder.create(env);
              // ...
              /* highlight-add-start */
              const ocm = ManagedClusterProvider.fromConfig(env.config, {
                logger: env.logger,
                scheduler: env.scheduler,
              });
              builder.addEntityProvider(ocm);
              /* highlight-add-start */
              // ...
            }
    2. packages/backend/src/plugins/catalog.ts 文件中直接添加一个调度

      ```ts title="packages/backend/src/index.ts"
            /* highlight-add-next-line */
            import { ManagedClusterProvider } from '@redhat/backstage-plugin-ocm-backend';
      
            export default async function createPlugin(
              env: PluginEnvironment,
            ): Promise<Router> {
              const builder = await CatalogBuilder.create(env);
              // ...
              /* highlight-add-start */
              const ocm = ManagedClusterProvider.fromConfig(env.config, {
                logger: env.logger,
                schedule: env.scheduler.createScheduledTaskRunner({
                  frequency: { minutes: 1 },
                  timeout: { minutes: 1 },
                }),
              });
              builder.addEntityProvider(ocm);
              /* highlight-add-start */
              // ...
            }
  6. 可选:为特定环境在目录中为集群实体配置默认所有者。例如,使用以下代码将 app-config.yaml catalog 部分中的 env 的集群所有者设置为来自 env 的所有者:

    `yaml title="app-config.yaml"
       catalog:
         providers:
           ocm:
             env:
               # highlight-next-line
               owner: user:foo

    有关默认所有者配置的更多信息,请参阅上游字符串参考文档

1.2.1.3. 设置 OCM 前端软件包
  1. 使用以下命令安装 OCM frontend 插件:

    yarn workspace app add @redhat/backstage-plugin-ocm
  2. 选择要使用的组件,例如:

    • OcmPage: 这是一个独立页面或仪表板,将所有集群显示为标题。您可以将 OcmPage 添加到 packages/app/src/App.tsx 文件中,如下所示:

      ```tsx title="packages/app/src/App.tsx"
           /* highlight-add-next-line */
           import { OcmPage } from '@redhat/backstage-plugin-ocm';
      
           const routes = (
             <FlatRoutes>
               {/* ... */}
               {/* highlight-add-next-line */}
               <Route path="/ocm" element={<OcmPage logo={<Logo />} />} />
             </FlatRoutes>
           );

      您还可以更新 packages/app/src/components/Root/Root.tsx 中的导航,如下所示:

      ```tsx title="packages/app/src/components/Root/Root.tsx"
           /* highlight-add-next-line */
           import StorageIcon from '@material-ui/icons/Storage';
      
           export const Root = ({ children }: PropsWithChildren<{}>) => (
             <SidebarPage>
               <Sidebar>
                 <SidebarGroup label="Menu" icon={<MenuIcon />}>
                   {/* ... */}
                   {/* highlight-add-next-line */}
                   <SidebarItem icon={StorageIcon} to="ocm" text="Clusters" />
                 </SidebarGroup>
                 {/* ... */}
               </Sidebar>
               {children}
             </SidebarPage>
           );
    • ClusterContextProvider :此组件是为 OCM 数据提供的 React 上下文,它与当前实体相关。ClusterContextProvider 组件用于显示 软件包/app/src/components/catalog/EntityPage.tsx 中提到的 React 组件中的任何数据

      ```tsx title="packages/app/src/components/catalog/EntityPage.tsx"
           /* highlight-add-start */
           import {
             ClusterAvailableResourceCard,
             ClusterContextProvider,
             ClusterInfoCard,
           } from '@redhat/backstage-plugin-ocm';
      
           /* highlight-add-end */
      
           const isType = (types: string | string[]) => (entity: Entity) => {
             if (!entity?.spec?.type) {
               return false;
             }
             return typeof types === 'string'
               ? entity?.spec?.type === types
               : types.includes(entity.spec.type as string);
           };
      
           export const resourcePage = (
             <EntityLayout>
               {/* ... */}
               {/* highlight-add-start */}
               <EntityLayout.Route path="/status" title="status">
                 <EntitySwitch>
                   <EntitySwitch.Case if={isType('kubernetes-cluster')}>
                     <ClusterContextProvider>
                       <Grid container direction="column" xs={6}>
                         <Grid item>
                           <ClusterInfoCard />
                         </Grid>
                         <Grid item>
                           <ClusterAvailableResourceCard />
                         </Grid>
                       </Grid>
                     </ClusterContextProvider>
                   </EntitySwitch.Case>
                 </EntitySwitch>
               </EntityLayout.Route>
               {/* highlight-add-end */}
             </EntityLayout>
           );
      
           export const entityPage = (
             <EntitySwitch>
               {/* ... */}
               {/* highlight-add-next-line */}
               <EntitySwitch.Case if={isKind('resource')} children={resourcePage} />
             </EntitySwitch>
           );

      在前面的代码块中,您可以将上下文供应商放在 资源 实体渲染器中,该适配器通常包括在 packages/app/src/components/catalog/EntityPage.tsx 或导入的组件中。

      • <ClusterInfoCard /> :这是在表中显示集群详情的实体组件:
      • <ClusterAvailableResourceCard /> :这是显示集群中可用资源的实体组件。例如,请参阅 ManagedCluster 资源的 .status.capacity

1.3. 对于用户

1.3.1. 在 Backstage 中使用 OCM 插件

OCM 插件将 Backstage 实例与多集群引擎集成,并从 OCM 显示实时数据。

1.3.1.1. 先决条件
1.3.1.2. 流程
  1. 打开 Backstage 应用程序。
  2. 点左侧面板中的 Clusters 选项卡查看 Managed Clusters 页面。

    Managed Clusters 页面显示包含额外信息的集群列表,如状态、基础架构供应商、关联的 OpenShift 版本和可用节点。

    ocm-plugin-ui

    您还可以使用 VERSION 列中的 Upgrade available 选项来升级集群的 OpenShift 版本。

  3. Managed Clusters 选择一个集群来查看相关的集群信息。

    您将被重定向到特定于集群的页面,其中包括:

    • 集群信息,如名称、状态、访问 Kubernetes 版本、关联的 OpenShift ID 和版本,以及访问的平台。
    • 可用 集群容量,包括 CPU 内核、内存大小和 pod 的数量。
    • 相关的链接,可让您直接访问不同的控制台,如 OpenShift 控制台、OCM 控制台和 OpenShift Cluster Manager 控制台。
    • 关系 卡,显示集群和相关依赖项的可视化表示。
    ocm-plugin-ui

第 2 章 为 Backstage 打开 Cluster Management 插件

Open Cluster Management (OCM)插件将 Backstage 实例与 OCM 集成。

有关 OCM 插件的更多信息,请参阅 GitHub 上的 Open Cluster Management 插件文档

第 3 章 为 Backstage 打开 Cluster Management 插件

Open Cluster Management (OCM)插件将 Backstage 实例与 OCM 集成。

有关 OCM 插件的更多信息,请参阅 GitHub 上的 Open Cluster Management 插件文档

法律通告

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部