2.2.2. 使用 CLI 安装 metering

您可以使用 OpenShift Container Platform CLI 安装 Metering Operator。

流程

  1. 为 Metering Operator 创建 Namespace 对象 YAML 文件。您必须使用 CLI 创建命名空间。例如, metering-namespace.yaml:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: openshift-metering 1
      annotations:
        openshift.io/node-selector: "" 2
      labels:
        openshift.io/cluster-monitoring: "true"
    1
    强烈建议在 openshift-metering 命名空间中部署 metering。
    2
    在为操作数 pod 配置特定的节点选择器前包括此注解。
  2. 创建 Namespace 对象:

    $ oc create -f <file-name>.yaml

    例如:

    $ oc create -f openshift-metering.yaml
  3. 创建 OperatorGroup 对象 YAML 文件。例如, metering-og:

    apiVersion: operators.coreos.com/v1
    kind: OperatorGroup
    metadata:
      name: openshift-metering 1
      namespace: openshift-metering 2
    spec:
      targetNamespaces:
      - openshift-metering
    1
    名称是任意名称。
    2
    指定 openshift-metering 命名空间。
  4. 创建一个 Subscription 对象 YAML 文件,以便为 Metering Operator 订阅一个命名空间。此对象以 redhat-operators 目录源中最新发布的版本为目标。例如, metering-sub.yaml:

    apiVersion: operators.coreos.com/v1alpha1
    kind: Subscription
    metadata:
      name: metering-ocp 1
      namespace: openshift-metering 2
    spec:
      channel: "4.6" 3
      source: "redhat-operators" 4
      sourceNamespace: "openshift-marketplace"
      name: "metering-ocp"
      installPlanApproval: "Automatic" 5
    1
    名称是任意名称。
    2
    您必须指定 openshift-metering 命名空间。
    3
    指定 4.6 作为频道。
    4
    指定包含 metering-ocp 软件包清单的 redhat-operators 目录源。如果 OpenShift Container Platform 集群安装在受限网络中(也称为断开连接的集群),请指定配置 Operator LifeCycle Manager (OLM) 时创建的 CatalogSource 对象的名称。
    5
    指定 "Automatic" 安装计划批准。