Chapter 3. Adding an OpenShift Container Platform source to cost management

To support cost management in Red Hat OpenShift Container Platform 4.6 and more recent versions, a new certified operator is introduced, Cost Management Metrics Operator.

Users on Red Hat OpenShift Container Platform 4.5 who want to use cost management can install the community operator koku-metrics-operator. See the Koku community documentation for installation and configuration instructions.

3.1. Installation tasks summary

Whether you are replacing a prior cost management operator with the Cost Management Metrics Operator or installing it for the first time, the basic tasks are the same.

Operator installation, configuration, and source management can all be performed from the OpenShift Container Platform web console.

You will perform the following tasks to install the Cost Management Metrics Operator and begin using the cost management application in OpenShift Container Platform.

Note

To install and configure Cost Management Metrics Operator from the OpenShift Container Platform web console, you must use an account with cluster administrator privileges.

Prerequisites

  • The OpenShift Container Platform cluster is installed.
  • You can access the OpenShift Container Platform web console using an account that has cluster administrator privileges.

Task summary

  • Install the Cost Management Metrics Operator (costmanagement-metrics-operator) and use the default token authentication.
  • Create a CostManagementMetricsConfig YAML file that configures costmanagement-metrics-operator
  • Create a cost management OpenShift Container Platform source with a new installation, or confirm an existing source with a replacement installation.
  • After installing the Cost Management Metrics Operator, delete the old cost operator. This task is required only when a previous cost management operator is installed.

If you use Basic authentication, additional steps are required to configure the Secret that holds username and password credentials.

3.2. Installing the cost operator

Install the Cost Management Metrics Operator from the OpenShift Container Platform web console.

Prerequisites

  • You are logged into the OpenShift Container Platform web console with cluster administrator privileges.

Procedure

  1. Login to the OpenShift Container Platform web console and click on the Operators > OperatorHub tab.
  2. Search for and locate Cost Management Metrics Operator.
  3. Click on the displayed Cost Management Metrics Operator tile.
  4. When the Install Operator window appears, you must select the costmanagement-metrics-operator namespace for installation. If the namespace does not yet exist, it is created for you.
  5. Click on the Install button.
  6. After a short wait, Cost Management Metrics Operator appears in the Installed Operators tab under Project: all projects or Project: costmanagement-metrics-operator.

3.3. Configuring the operator instance for a new installation

Use the OpenShift Container Platform web console to configure the costmanagement-metrics-operator instance after it is installed.

Prerequisites

  • You are logged into the OpenShift Container Platform web console with cluster administrator privileges.
  • The Cost Management Metrics Operator appears in the Installed Operators tab.

Procedure

  1. Under the Name heading in the list of installed operators, click the Cost Management Metrics Operator link. The Installed Operators > Operator Details window appears for Cost Management Metrics Operator.
  2. In the Details window, click + Create Instance.
  3. A Cost Management Metrics Operator > Create CostManagementMetricsConfig window appears.
  4. Click the YAML view radio button to view and modify the contents of the YAML configuration file.
  5. When you create a new cost management instance for the Cost Management Metrics Operator, make the following modifications in the YAML configuration file.
  6. Locate the following two lines in the YAML file.

        create_source: false
        name: INSERT-SOURCE-NAME
    1. Change false to true.
    2. Change INSERT-SOURCE-NAME to the new name of your source.

      Example

          create_source: true
          name: my-cost-source

  7. Click the Create button. These actions create a new source for cost management that will appear in the cloud.redhat.com cost management application.

3.4. Replacing a prior operator instance

If you are replacing a prior cost management operator with the Cost Management Metrics Operator, make certain your existing cost management source is properly configured in the YAML configuration file.

Important

When you are replacing a prior cost management operator with the Cost Management Metrics Operator and you want to use an existing source, you must make certain that the name: INSERT-SOURCE-NAME in the YAML file matches your existing source.

Prerequisites

  • You are logged into the OpenShift Container Platform web console with cluster administrator privileges.
  • You can access cloud.redhat.com and view existing cost management sources.

Procedure

  1. Under the Name heading in the list of installed operators, click the Cost Management Metrics Operator link. The Installed Operators > Operator Details window appears for Cost Management Metrics Operator.
  2. In the Details window, click + Create Instance.
  3. A Cost Management Metrics Operator > Create CostManagementMetricsConfig window appears.
  4. Click the YAML view radio button to view and modify the contents of the CostManagementMetricsConfig YAML file.
  5. Open cloud.redhat.com and log in using your Organization Administrator account.
  6. Click on configuration gear (Settings).
  7. Click on the Sources tab to display existing sources.
  8. Select an existing cost management source and copy its name.
  9. In the CostManagementMetricsConfig YAML file, replace INSERT-SOURCE-NAME with the source name that you copied from the cost management source list for your organization.

        create_source: false
        name: INSERT-SOURCE-NAME    <<<< replace this string

    The create_source: false does not change because you are matching an existing source, not creating a new source.

  10. Click the Create button. No further actions are needed to configure the operator instance.

3.5. Removing a prior cost operator

After installing the costmanagement-metrics-operator, uninstall the prior cost management operator.

To avoid gaps in your cost management data, you can wait 24 to 48 hours before removing the prior operator while you verify that costmanagement-metrics-operator provides cost management reports.

Note

If you mistakenly remove the Cost Management Metrics Operator, reinstall it.

Prerequisites

  • A prior cost management operator is installed.
  • You installed the Cost Management Metrics Operator.
  • You are logged into the OpenShift Container Platform web console with cluster administrator privileges.
  • You can view the operators in the Installed Operators tab.

Procedure

  1. In the Installed Operators list, select the operator you want to remove.
  2. Click the Options menu more options in that row.
  3. Click on the Uninstall Operator option. Confirm the action to remove the operator.
  4. In the OpenShift Container Platform web console, click the Administration > Custom Resource Definitions tab.
  5. In the window that displays the custom resource definitions (CRD), locate the CostManagement CRD and the CostManagementData CRD for cost-mgmt-operator or the KokuMetricsConfig CRD for koku-metrics-operator.
  6. For each CRD, click the Options menu more optionsDelete Custom Resource Definition. Confirm the delete action.
  7. When these CRDs are deleted, the prior operator is fully uninstalled.
Note

When you install Cost Management Metrics Operator, a CostManagementMetricsConfig CRD appears in Administration > Custom Resource Definitions list.

3.6. Verifying the cost operator

View the configuration YAML file to verify the cost management operator is functioning.

Prerequisites

  • You can access the OpenShift Container Platform web console.
  • You can locate and view the Installed Operators tab.

Procedure

  1. Click on the Installed Operators tab.
  2. In the list of installed operators, click on the Cost Management Metrics Operator entry.
  3. When the metrics operator window opens, click on the CostManagementMetricsConfig tab to show a list of the configuration file names.
  4. In the name list, click on the configuration file. In the default installation, the file name is costmanagementmetricscfg-sample.
  5. When the Details window opens, click on the YAML tab. and visually check the following items.

    1. Prometheus configuration and connection are true.

        prometheus:
          last_query_start_time: '2021-01-25T20:59:06Z'
          last_query_success_time: '2021-01-25T20:59:06Z'
          prometheus_configured: true
          prometheus_connected: true
          service_address: 'https://thanos-querier.openshift-monitoring.svc:9091'
          skip_tls_verification: false
    2. Upload information shows the ingress path, successful upload and time, and accepted status.

       upload:
          ingress_path: /api/ingress/v1/upload
          last_successful_upload_time: '2021-01-25T20:59:35Z'
          last_upload_status: 202 Accepted
          last_upload_time: '2021-01-25T20:59:35Z'
          upload: true
          upload_cycle: 360
          upload_wait: 28
          validate_cert: true

3.7. Configuring basic authentication for cost operator

You can configure the cost operator to use basic authentication. By default, the cost operator uses token authentication.

There are two procedures required when you configure basic authentication.

3.7.1. Creating the secret key/value pair for basic authentication

Prerequisites

  • You are logged into the OpenShift Container Platform web console with cluster administrator privileges.
  • The Cost Management Metrics Operator appears in the Installed Operators tab.
  • You have a username and password for your cloud.redhat.com account.

Procedure

This procedure describes setting up basic authentication using the OpenShift Container Platform web console.

  1. In the OpenShift Container Platform web console, click on the Workloads > Secrets tab.
  2. In the Secrets window, select Project:costmanagement-metrics-operator from the dropdown.
  3. Click the Create > Key/Value Secret selection.
  4. In the Create Key/Value Secret window enter the following information to create a new secret that contains a username key and a password key and a value for each key.

    1. Enter a name for your secret in the Secret Name field.

      Secret name example

      basic-auth-secret

    2. In the Key field, enter username. This is your first key of the key pair.

      Key name example for username

      username

    3. In the Value field for the username key, enter the actual username for your authorized cloud.redhat.com user account.

      Key value example for username

      RedHatUser

    4. Click the Add Key/Value link to add the required password key name and value.
    5. In the Key field, enter password. This is your second key of the key pair.

      Key name example for password

      password

    6. In the Value field for the password key, enter the actual password for your authorized cloud.redhat.com user account.

      Key value example for password

      my.User!password

    7. Click the Create button to complete the creation of your basic authorization secret.
    8. After you click the Create button, you can verify the key information details for the secret.

      Note

      Do not add the secret to the workload.

3.7.2. Modifying the YAML file

Modify the Cost Management Metrics Operator API YAML file to use basic authentication with a secret username and password key/value pair.

Prerequisites

  • You are logged into the OpenShift Container Platform web console with cluster administrator privileges.
  • You created a secret name for the username and password key/value pair.
  • The Cost Management Metrics Operator is installed.

Procedure

  1. Click on the Operators > Installed Operators tab.
  2. Locate the row that contains Cost Management Metrics Operator and click on the Cost Management Metrics Operator link that is under the Provided APIs heading.
  3. When the CostManagementMetricsConfig window appears, click on the configuration file listed in the Name column.

    The default name is costmanagementmetricscfg-sample.

  4. When the costmanagementmetricscfg-sample window appears, click in the YAML tab to open an edit and view window.
  5. Locate the following lines in the YAML view.

      authentication:
        type: token
  6. Change type: token to type: basic.
  7. Insert a new line for secret_name. Enter the value for secret_name, which is the name you previously created.

    Example

      authentication:
        secret_name: basic-auth-secret
        type: basic

  8. Click the Save button. A confirmation message appears.

3.8. Creating an Openshift Container Platform source manually

If you follow the previous steps, your OpenShift Container Platform source should be created automatically. However, there are situations, such as restricted network installations, when an OpenShift Container Platform source must be created manually on cloud.redhat.com.

Prerequisites

  • OpenShift Container Platform cluster installed.
  • Red Hat account user with Organization Administrator entitlements.
  • You are logged into the OpenShift Container Platform web console.

Procedure

  1. From cost management, click configuration gear (Settings).
  2. Click Sources.
  3. Click Red Hat Sources.
  4. Click Add source to open the dialog.
  5. Enter a name for the source and click Next.
  6. Select the Red Hat OpenShift Container Platform tile as the source type.
  7. Select cost management as the application and click Next.
  8. Copy your Cluster Identifier from the OpenShift Container Platform web console Home > Overview tab and click Next.
  9. Review the details and click Add to create the source.

3.9. Adding a restricted network source

You can install OpenShift Container Platform on a restricted network that does not have access to the internet.

The procedure to add an OpenShift Container Platform cluster operating on a restricted network as a cost management source is different in the following ways:

  1. Operator Lifecycle Manager is configured to install and run local sources.
  2. The costmanagement-metrics-operator is configured to store cost report CSV files locally using a persistent volume claim (PVC).
  3. Cost reports stored in the PVC are downloaded to a workstation.
  4. An OpenShift Container Platform source is created manually.
  5. Cost reports are uploaded to cloud.redhat.com from your workstation.

3.9.1. Installing the cost management operator on a restricted network

For OpenShift Container Platform clusters that are installed on restricted networks, Operator Lifecycle Manager (OLM) by default cannot access the costmanagement-metrics-operator hosted remotely because those remote sources require full Internet connectivity. Therefore, OLM must be configured to install and run local sources.

Prerequisites

  • OpenShift Container Platform cluster installed.
  • Workstation with unrestricted network access.
  • You are logged into the OpenShift Container Platform web console with cluster administrator privileges.

Procedure

  1. Complete the following OpenShift Container Platform procedure to create a local mirror of the costmanagement-metrics-operator: Using Operator Lifecycle Manager on restricted networks.

    Note

    The costmanagement-metrics-operator is found in the redhat-operators catalog in the registry.redhat.io/redhat/redhat-operator-index:v4.7 index.

    Red Hat recommends pruning unwanted objects from the index before pushing to the mirrored registry. Make sure you keep the costmanagement-metrics-operator package.

  2. Log in to the OpenShift Container Platform web console and click Operators > OperatorHub.
  3. Search for and locate Cost Management Metrics Operator.
  4. Click the Cost Management Metrics Operator tile.
  5. When the Install Operator window appears, you must select the costmanagement-metrics-operator namespace for installation. If the namespace does not yet exist, it is created for you.
  6. Click Install.

Verification steps

  • After a short wait, Cost Management Metrics Operator appears in the Installed Operators tab under Project: all projects or Project: costmanagement-metrics-operator.

Additional resources

3.9.2. Configuring Cost Operator on a restricted network

After the costmanagement-metrics-operator is installed, you must configure it to run on a restricted network.

Prerequisites

  • costmanagement-metrics-operator installed.
  • You are logged into the OpenShift Container Platform web console with cluster administrator privileges.

Procedure

  1. From the OpenShift Container Platform web console, select Operators > Installed Operators > costmanagement-metrics-operator > CostManagementMetricsConfig > Create Instance.
  2. Specify the desired storage. If not specified, the operator will create a default persistent volume claim called costmanagement-metrics-operator-data with 10Gi of storage.

    Note

    To configure the costmanagement-metrics-operator to use or create a different PVC, update the volume_claim_template configuration in YAML view.

  3. Select YAML view.
  4. Specify the maximum number of reports to store using max_reports_to_store, and time between report generation in minutes using upload_cycle.

        packaging:
          max_reports_to_store: 30
          max_size_MB: 100
        upload:
          upload_cycle: 360
    Important

    The costmanagement-metrics-operator creates one report every 360 minutes by default. Therefore, the default value of 30 reports and 360 minutes gives you 7.5 days of reports.

    Any report generated after the total number specified will replace the oldest report in storage. Make sure to download generated reports from your PVC before they are lost.

  5. Set upload_toggle to false.

        upload:
          upload_cycle: 360
          upload_toggle: false
  6. Replace the configuration in the source section with empty brackets.

        source: {}
  7. Replace the configuration in the authentication section with empty brackets.

        authentication: {}
  8. Click Create.

Verification steps

  1. Select the CostManagementMetricsConfig you created.
  2. Select YAML view.
  3. Verify that a report has been created in the packaging section.

        packaging:
          last_successful_packaging_time: `current date and time`
          max_reports_to_store: 30
          max_size_MB: 100
          number_of_reports_stored: 1
          packaged_files:
            - >-
                /tmp/costmanagement-metrics-operator-reports/upload/YYYYMMDDTHHMMSS-cost-mgmt.tar.gz
    Note

    costmanagement-metrics-operator will generate an initial report after it is configured. Generated reports will be listed under packaged_files.

3.9.3. Downloading cost reports

If the costmanagement-metrics-operator is configured to run in a restricted network, copy the reports from the PVC where they are temporarily stored to a workstation with unrestricted network access for upload to cloud.redhat.com.

Note

The default configuration saves one week of reports. Therefore, download the reports locally and upload them to cloud.redhat.com weekly to prevent loss of metrics data.

Prerequisites

  • Workstation with unrestricted network access.
  • costmanagement-metrics-operator reports in your PVC.

Procedure

  1. Create the following pod with claimName matching the PVC containing the report data:

    kind: Pod
    apiVersion: v1
    metadata:
      name: volume-shell
      namespace: costmanagement-metrics-operator
    spec:
      volumes:
      - name: costmanagement-metrics-operator-reports
        persistentVolumeClaim:
          claimName: costmanagement-metrics-operator-data
      containers:
      - name: volume-shell
        image: busybox
        command: ['sleep', '3600']
        volumeMounts:
        - name: costmanagement-metrics-operator-reports
          mountPath: /tmp/costmanagement-metrics-operator-reports
  2. Use rsync to copy all of the files from the PVC to a local folder.

    $ oc rsync volume-shell:/tmp/costmanagement-metrics-operator-reports/upload local/path/to/save/folder
  3. Confirm that the files have been copied.
  4. Connect to the pod and delete the contents of the upload folder.

    $ oc rsh volume-shell
    $ rm /tmp/costmanagement-metrics-operator-reports/upload/*
  5. (Optional) Delete the pod that was used to connect to the PVC.

    $ oc delete -f volume-shell.yaml

Additional resources

3.9.4. Uploading cost reports to cloud.redhat.com

You must manually upload locally stored cost reports from a restricted network to cloud.redhat.com.

Note

The default configuration saves one week of reports. Therefore, download the reports locally and upload them to cloud.redhat.com weekly to prevent loss of metrics data.

Prerequisites

Procedure

  • Upload your reports to cloud.redhat.com, replacing USERNAME and PASSWORD with your cloud.redhat.com login credentials, and FILE_NAME with the report to upload:

    $ curl -vvvv -F "file=@FILE_NAME.tar.gz;type=application/vnd.redhat.hccm.tar+tgz"  https://cloud.redhat.com/api/ingress/v1/upload -u USERNAME:PASS

Verification steps

  1. From cloud.redhat.com/cost-management, click OpenShift.
  2. Verify you have OpenShift usage data for your cluster on the OpenShift details page.