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
-
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
-
Create an
OperatorGroup object and a subscription object.
-
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.
-
Retrieve your
client_id and client_secret from the Red Hat Hybrid Cloud Console service account.
-
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
-
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
-
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>
-
Deploy your secret YAML file with the following command:
-
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
-
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
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.