Install the cost management Metrics Operator with the OpenShift CLI

When automating cluster creation, use the OpenShift CLI to install the Cost Management Metrics Operator and create your cluster integration. If using service authentication, configure the Operator accordingly.

Before you begin

  • You installed the OpenShift CLI, oc.
  • You have cluster administrator privileges for your OpenShift Container Platform cluster.
  • You can access the Red Hat Hybrid Cloud Console with an account that has access to the cost management service. See Limiting access to cost management resources for more information.

Procedure

  1. To verify the package manifests have the supported install modes and available channels, enter the following command:
    oc describe packagemanifests costmanagement-metrics-operator -n openshift-marketplace
  2. Create an OperatorGroup object and a subscription object.
  3. If you are not using token authentication, configure your Operator to use service account authorization. To use this method, add your service account to a User Access Group that has a Cloud Administrator role. Ensure the service account inherits the permissions of the user group. For more information, see Limiting access to cost management resources.
    1. Retrieve your client_id and client_secret from the Red Hat Hybrid Cloud Console service account.
    2. Encode the value of your service account’s client_id in base64. In your terminal, enter:
      echo -n "<red_hat_service_account_client_id>" | base64
    3. Encode the value of your service account’s client_secret in base64. In your terminal, enter:
      echo -n "<red_hat_service_account_client_secret>" | base64
  4. Create a YAML file to store your secrets. Paste the client_id and client_secret in the data.client_id and data.client_secret fields.

    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>
  5. Deploy your secret YAML file with the following command:
    oc apply -f example.yaml
  6. To use service authentication for the cost management Operator, edit the custom resource definition for the Operator. You must edit the custom resource example YAML so that authentication.type is set to service-account. You must also add a line so that authentication.secret_name is set to the name of your secret. In this earlier example, the name of the secret is service-account-auth-secret.

    Custom resource example

    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
  7. To create an integration automatically without using the wizard in Red Hat Hybrid Cloud Console, edit the custom resource example YAML so that source.create_source is set to true and source.name is set to a name. In this example, the name is set to cluster2.

    Source creation example

    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

Results

  • Run the following command to verify that the operator is installed:
    oc get csv -n costmanagement-metrics-operator

    The output shows the Cost Management Metrics Operator with status Succeeded.

  • If you set create_source to true, verify that the integration was created in Red Hat Hybrid Cloud Console under Settings > Integrations > Red Hat.

What to do next

If you use a proxy with a custom CA certificate, you must create additional configurations to inject this certificate into Cost Management Metrics Operator. For more details, see Injecting a custom CA certificate in the OpenShift Container Platform documentation.