Home GitHub

IMPORTANT NOTE: This site is not official Red Hat documentation and is provided for informational purposes only. These guides may be experimental, proof of concept, or early adoption. Officially supported documentation is available at docs.openshift.com and access.redhat.com.

Red Hat Cost Management for Cloud Services

Author: Charlotte Fung

Last edited: 09/05/2022

Adopted from Official Documentation for Cost Management Service

Red Hat Cost Management is a software as a service (SaaS) offering available free of charge as part of your Red Hat subscriptions. Cost management helps you monitor and analyze your OpenShift Container Platform and Public cloud costs in order to improve the management of your business.

Some capabilities of cost management are :

In this document, I will show you how to connect your OpenShift and Cloud provider sources to Cost Management in order to collect cost and usage.

Prerequisites

Adding your OpenShift source to Cost Management

Installing the Cost Management Metric Operator

  1. Log into the Openshift cluster web console with cluster-admin credentials

  2. On the left navigation pane under Administator perspective, select Operators –> OperatorHub

    Operators view

  3. Search for and locate cost management metrics operator. Click on the displayed Cost Management Metrics Operator

    Operatorhub

  4. When the Install Operator window appears, you must select the costmanagement-metrics-operator namespace for installation. If it does not exist, it will be created for you. Click on install button.

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

Configuring the Operator instance for a new installation

  1. Once installed, click on the Cost Management

  2. In the detail 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

    Cost management Metrics Config

  5. Modify the following two lines in the YAML file to look like the following

    Change SOURCE-NAME to the new name of your source (ex. my-openshift-cost-source)

    create_source: true
    name: <SOURCE-NAME>
    
  6. Click the Create button. This creates a new source for cost management that will appear in the console.redhat.com Cost Management applications

Adding your Microsoft Azure source to Cost Management

1. Creating a Microsoft Azure Source in your Red Hat account

  1. In the console.redhat.com click on All apps and services tab in the left top corner of the screen to navigate to this window. Click on Sources under Settings

    Access Sources link

  2. On Sources page, click on Cloud sources tab and then click Add a source. This opens up the Sources Wizard

  3. Enter a name for your source and click next

  4. Select cost management as the application and Microsoft Azure as the source type.

  5. Click Next. We will create the storage account and resource group in Azure account before proceeding. Keep this window open.

2. Configuring your Microsoft Azure

The following steps are required to configure your Azure account to be a cost management source

  1. Creating a storage account and resource group
  2. Configuring a storage account contributor and reader roles for access
  3. Scheduling daily exports

2.1 Creating an Azure resource group and storage account using Azure CLI

  1. First create a new resource group

    az group create \
     --name storage-resource-group \
     --location eastus
    
  2. If you’re not sure which region to specify for the --location parameter, you can retrieve a list of supported regions for your subscription with the az account list-locations command.

    az account list-locations \
     --query "[].{Region:name}" \
     --out table
    
  3. Next, create a standard general-purpose v2 storage account with read-access geo-redundant storage. Ensure the name of your storage account is unique across Azure

    az storage account create \
     --name <account-name> \
     --resource-group storage-resource-group \
     --location eastus \
     --sku Standard_RAGRS \
     --kind StorageV2
    
  4. Make note of the resource group and storage account. We will need them in the subsequent steps

  5. Return to Sources wizard in console.redhat.com, enter the Resource group name and Storage account name and click Next. Leave this window for now and proceed to next step below.

2.2 Configuring Azure roles using Azure CLI

We need to grant cost management read-only access to Azure cost data by configuring a Storage Account Contributor and Reader role in Azure

  1. Run the following command to obtain your Subscription ID:

    SUBSCRIPTION=$(az account show --query "{subscription_id: id}" -o tsv)
    
  2. Return to the console.redhat.com Sources wizard, enter your Subscription ID. Click Next to move to the next screen

  3. In Azure CLI, create a cost management Storage Account Contributor role, an obtain your tenant ID, client (application) ID, and client secret

     az ad sp create-for-rbac -n "CostManagement" \
       --role "Storage Account Contributor" \
       --query '{"tenant": tenant, "client_id": appId, "secret": password}'
    
  4. Return to Sources wizard in console.redhat.com, enter your Azure Tenant ID, Client ID, and Client Secret.

  5. Run the following command to create cost management Reader role with your subscription ID. Copy the full command from the Sources wizard, which will automatically substitute your Azure subscription ID obtained earlier.

    az role assignment create --role "Cost Management Reader" \
      --assignee http://CostManagement --subscription ${SUBSCRIPTION}
    
  6. Click Next in Sources wizard.

2.3 Configuring a Daily Azure data export schedule using Azure Portal

Cost management requires a data export from a Subscription level scope

  1. In the Azure Portal home page, click on Subscriptions

    Azure Portal home page

  2. Select the Subscription you want to track from the list, and then select Cost Analysis in the menu. At the top of the Cost analysis page, select configure subscription

    Cost Analysis view

  3. Click on the Export tab, and then Schedule export

    Schedule export

  4. In the Exports wizard, fill out the Export details

    Export details

    • For Export Type, select Daily export of billing-period-to-date costs

    • For Storage account, select the account you created earlier

    • Enter any value for the Container name and Directory path for the export. These values provide the tree structure in the storage account where report files are stored.

    • Click Create to start exporting data to the Azure storage container.

  5. Return to Sources wizard after creating the export schedule and click Next. Review the source details

  6. Click Finish to complete adding the Azure source to cost management

Cost management will begin polling Azure for cost data, which will appear on the cost management dashboard (console.redhat.com/openshift/cost-management/).

Managing your Costs

After adding your Openshift Container Platform and Cloud Provider sources, Cost management will show cost data by

  1. Source

  2. Cloud provider cost and usage related to running your OpenShift Container Platform clusters on their platform

    See the following video for a quick overview of Cost Management for OpenShift followed by a demo of the product

Next steps for managing your costs

  1. Limiting access to cost management resources - Use role-based access control to limit visibility of resources in cost management reports.

  2. Managing cost data using tagging - Tags allow you to organize your resources by cost and allocate the costs to different parts of your cloud infrastructure

  3. Using cost models - Configure cost models to associate prices to metrics and usage.

  4. Visualizing your costs using Cost Explorer - Allows you to see your costs through time.