1.3. 可选:使用 CLI 安装成本管理 Operator


如果要自动创建集群,可以选择使用 OpenShift CLI 而不是 OperatorHub 安装 Cost Management Metrics Operator。在 OpenShift Container Platform CLI 中,您可以以成本管理为 OpenShift Container Platform 集群创建集成。如果使用服务身份验证,您必须将 Operator 配置为使用它。

先决条件

  • 已安装 OpenShift CLI oc
  • 具有 OpenShift Container Platform 集群的集群管理员特权。

流程

  1. 要验证软件包清单是否有支持的安装模式和可用频道,请输入以下命令:

    oc describe packagemanifests costmanagement-metrics-operator -n openshift-marketplace
  2. 创建 OperatorGroup 对象和订阅对象。

  3. 如果不使用令牌身份验证,请将 Operator 配置为使用服务帐户授权。要使用此方法,请将服务帐户添加到具有 Cloud Administrator 角色的用户访问组中。确保服务帐户继承用户组的权限。

    • 如需更多信息,请参阅 限制成本管理资源的权限

      1. 红帽混合云控制台服务帐户 检索您的 client_idclient_secret
      2. 使用 base64 对服务帐户的 client_id 值进行编码。在终端中,输入:

        echo -n "<red_hat_service_account_client_id>" | base64
      3. 对服务帐户的 'client_secret'in base64 编码值。在终端中,输入:

        echo -n "<red_hat_service_account_client_secret>" | base64
  4. 创建 YAML 文件来存储您的 secret。将 client_idclient_secret 粘贴到 data.client_iddata.client_secret 字段中。

    example.yaml

    kind: Secret
    apiVersion: v1
    metadata:
      name: service-account-auth-secret
      namespace: costmanagement-metrics-operator
    data:
      client_id: <base64_encoded_red_hat_service_account_client_id>
      client_secret: <base64_encoded_red_hat_service_account_client_secret>

    1. 使用以下命令部署 secret YAML 文件:

      oc apply -f example.yaml
  5. 要将服务身份验证用于成本管理 Operator,请编辑 Operator 的自定义资源定义。您必须编辑自定义资源示例 YAML,以便将 authentication.type 设置为 service-account。您还必须添加一行,以便将 authentication.secret_name 设置为 secret 的名称。在前面的示例中,机密的名称是 service-account-auth-secret

    自定义资源示例

    kind: CostManagementMetricsConfig
    apiVersion: costmanagement-metrics-cfg.openshift.io/v1beta1
    metadata:
      name: costmanagementmetricscfg-sample-v1beta1
      namespace: costmanagement-metrics-operator
    spec:
      authentication:
        type: service-account
        secret_name: service-account-auth-secret
      packaging:
        max_reports_to_store: 30
        max_size_MB: 100
      prometheus_config:
        collect_previous_data: true
        context_timeout: 120
        disable_metrics_collection_cost_management: false
        disable_metrics_collection_resource_optimization: false
      source:
        check_cycle: 1440
        create_source: false
        name: ''
      upload:
        upload_cycle: 360
        upload_toggle: true

  6. 要在不使用 Red Hat Hybrid Cloud Console 中的向导的情况下自动创建集成,请编辑自定义资源示例 YAML,以便 source.create_source 设置为 true,将 source.name 设置为 name。在本例中,名称设置为 cluster2

    源创建示例

    kind: CostManagementMetricsConfig
    apiVersion: costmanagement-metrics-cfg.openshift.io/v1beta1
    metadata:
      name: costmanagementmetricscfg-sample-v1beta1
      namespace: costmanagement-metrics-operator
    spec:
      authentication:
        type: service-account
        secret_name: service-account-auth-secret
      packaging:
        max_reports_to_store: 30
        max_size_MB: 100
      prometheus_config:
        collect_previous_data: true
        context_timeout: 120
        disable_metrics_collection_cost_management: false
        disable_metrics_collection_resource_optimization: false
      source:
        check_cycle: 1440
        create_source: true
        name: 'cluster2'
      upload:
        upload_cycle: 360
        upload_toggle: true

重要

如果带有自定义 CA 证书的代理,必须创建额外的配置来将此证书注入 Cost Management Metrics Operator。如需了解更多详细信息,请参阅 OpenShift Container Platform 文档中的 注入自定义 CA 证书

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.