This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 4. Configuring metering
4.1. About configuring metering Link kopierenLink in die Zwischenablage kopiert!
Metering is a deprecated feature. Deprecated functionality is still included in OpenShift Container Platform and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.
For the most recent list of major functionality that has been deprecated or removed within OpenShift Container Platform, refer to the Deprecated and removed features section of the OpenShift Container Platform release notes.
The MeteringConfig custom resource specifies all the configuration details for your metering installation. When you first install the metering stack, a default MeteringConfig custom resource is generated. Use the examples in the documentation to modify this default file. Keep in mind the following key points:
- At a minimum, you need to configure persistent storage and configure the Hive metastore.
- Most default configuration settings work, but larger deployments or highly customized deployments should review all configuration options carefully.
- Some configuration options can not be modified after installation.
For configuration options that can be modified after installation, make the changes in your MeteringConfig custom resource and reapply the file.
4.2. Common configuration options Link kopierenLink in die Zwischenablage kopiert!
Metering is a deprecated feature. Deprecated functionality is still included in OpenShift Container Platform and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.
For the most recent list of major functionality that has been deprecated or removed within OpenShift Container Platform, refer to the Deprecated and removed features section of the OpenShift Container Platform release notes.
4.2.1. Resource requests and limits Link kopierenLink in die Zwischenablage kopiert!
You can adjust the CPU, memory, or storage resource requests and/or limits for pods and volumes. The default-resource-limits.yaml below provides an example of setting resource request and limits for each component.
4.2.2. Node selectors Link kopierenLink in die Zwischenablage kopiert!
You can run the metering components on specific sets of nodes. Set the nodeSelector on a metering component to control where the component is scheduled. The node-selectors.yaml file below provides an example of setting node selectors for each component.
Add the openshift.io/node-selector: "" namespace annotation to the metering namespace YAML file before configuring specific node selectors for the operand pods. Specify "" as the annotation value.
Add the openshift.io/node-selector: "" namespace annotation to the metering namespace YAML file before configuring specific node selectors for the operand pods. When the openshift.io/node-selector annotation is set on the project, the value is used in preference to the value of the spec.defaultNodeSelector field in the cluster-wide Scheduler object.
Verification
You can verify the metering node selectors by performing any of the following checks:
Verify that all pods for metering are correctly scheduled on the IP of the node that is configured in the
MeteringConfigcustom resource:Check all pods in the
openshift-meteringnamespace:oc --namespace openshift-metering get pods -o wide
$ oc --namespace openshift-metering get pods -o wideCopy to Clipboard Copied! Toggle word wrap Toggle overflow The output shows the
NODEand correspondingIPfor each pod running in theopenshift-meteringnamespace.Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Compare the nodes in the
openshift-meteringnamespace to each nodeNAMEin your cluster:oc get nodes
$ oc get nodesCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verify that the node selector configuration in the
MeteringConfigcustom resource does not interfere with the cluster-wide node selector configuration such that no metering operand pods are scheduled.Check the cluster-wide
Schedulerobject for thespec.defaultNodeSelectorfield, which shows where pods are scheduled by default:oc get schedulers.config.openshift.io cluster -o yaml
$ oc get schedulers.config.openshift.io cluster -o yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3. Configuring persistent storage Link kopierenLink in die Zwischenablage kopiert!
Metering is a deprecated feature. Deprecated functionality is still included in OpenShift Container Platform and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.
For the most recent list of major functionality that has been deprecated or removed within OpenShift Container Platform, refer to the Deprecated and removed features section of the OpenShift Container Platform release notes.
Metering requires persistent storage to persist data collected by the Metering Operator and to store the results of reports. A number of different storage providers and storage formats are supported. Select your storage provider and modify the example configuration files to configure persistent storage for your metering installation.
4.3.1. Storing data in Amazon S3 Link kopierenLink in die Zwischenablage kopiert!
Metering can use an existing Amazon S3 bucket or create a bucket for storage.
Metering does not manage or delete any S3 bucket data. You must manually clean up S3 buckets that are used to store metering data.
Procedure
Edit the
spec.storagesection in thes3-storage.yamlfile:Example
s3-storage.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specify the name of the bucket where you would like to store your data. Optional: Specify the path within the bucket.
- 2
- Specify the region of your bucket.
- 3
- The name of a secret in the metering namespace containing the AWS credentials in the
data.aws-access-key-idanddata.aws-secret-access-keyfields. See the exampleSecretobject below for more details. - 4
- Set this field to
falseif you want to provide an existing S3 bucket, or if you do not want to provide IAM credentials that haveCreateBucketpermissions.
Use the following
Secretobject as a template:Example AWS
SecretobjectCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe values of the
aws-access-key-idandaws-secret-access-keymust be base64 encoded.Create the secret:
oc create secret -n openshift-metering generic my-aws-secret \ --from-literal=aws-access-key-id=my-access-key \ --from-literal=aws-secret-access-key=my-secret-key
$ oc create secret -n openshift-metering generic my-aws-secret \ --from-literal=aws-access-key-id=my-access-key \ --from-literal=aws-secret-access-key=my-secret-keyCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis command automatically base64 encodes your
aws-access-key-idandaws-secret-access-keyvalues.
The aws-access-key-id and aws-secret-access-key credentials must have read and write access to the bucket. The following aws/read-write.json file shows an IAM policy that grants the required permissions:
Example aws/read-write.json file
If spec.storage.hive.s3.createBucket is set to true or unset in your s3-storage.yaml file, then you should use the aws/read-write-create.json file that contains permissions for creating and deleting buckets:
Example aws/read-write-create.json file
4.3.2. Storing data in S3-compatible storage Link kopierenLink in die Zwischenablage kopiert!
You can use S3-compatible storage such as Noobaa.
Procedure
Edit the
spec.storagesection in thes3-compatible-storage.yamlfile:Example
s3-compatible-storage.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the following
Secretobject as a template:Example S3-compatible
SecretobjectCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3.3. Storing data in Microsoft Azure Link kopierenLink in die Zwischenablage kopiert!
To store data in Azure blob storage, you must use an existing container.
Procedure
Edit the
spec.storagesection in theazure-blob-storage.yamlfile:Example
azure-blob-storage.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the following
Secretobject as a template:Example Azure
SecretobjectCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the secret:
oc create secret -n openshift-metering generic my-azure-secret \ --from-literal=azure-storage-account-name=my-storage-account-name \ --from-literal=azure-secret-access-key=my-secret-key
$ oc create secret -n openshift-metering generic my-azure-secret \ --from-literal=azure-storage-account-name=my-storage-account-name \ --from-literal=azure-secret-access-key=my-secret-keyCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3.4. Storing data in Google Cloud Storage Link kopierenLink in die Zwischenablage kopiert!
To store your data in Google Cloud Storage, you must use an existing bucket.
Procedure
Edit the
spec.storagesection in thegcs-storage.yamlfile:Example
gcs-storage.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the following
Secretobject as a template:Example Google Cloud Storage
SecretobjectCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the secret:
oc create secret -n openshift-metering generic my-gcs-secret \ --from-file gcs-service-account.json=/path/to/my/service-account-key.json
$ oc create secret -n openshift-metering generic my-gcs-secret \ --from-file gcs-service-account.json=/path/to/my/service-account-key.jsonCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.4. Configuring the Hive metastore Link kopierenLink in die Zwischenablage kopiert!
Metering is a deprecated feature. Deprecated functionality is still included in OpenShift Container Platform and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.
For the most recent list of major functionality that has been deprecated or removed within OpenShift Container Platform, refer to the Deprecated and removed features section of the OpenShift Container Platform release notes.
Hive metastore is responsible for storing all the metadata about the database tables created in Presto and Hive. By default, the metastore stores this information in a local embedded Derby database in a persistent volume attached to the pod.
Generally, the default configuration of the Hive metastore works for small clusters, but users may wish to improve performance or move storage requirements out of cluster by using a dedicated SQL database for storing the Hive metastore data.
4.4.1. Configuring persistent volumes Link kopierenLink in die Zwischenablage kopiert!
By default, Hive requires one persistent volume to operate.
hive-metastore-db-data is the main persistent volume claim (PVC) required by default. This PVC is used by the Hive metastore to store metadata about tables, such as table name, columns, and location. Hive metastore is used by Presto and the Hive server to look up table metadata when processing queries. You remove this requirement by using MySQL or PostgreSQL for the Hive metastore database.
To install, Hive metastore requires that dynamic volume provisioning is enabled in a storage class, a persistent volume of the correct size must be manually pre-created, or you use a pre-existing MySQL or PostgreSQL database.
4.4.1.1. Configuring the storage class for the Hive metastore Link kopierenLink in die Zwischenablage kopiert!
To configure and specify a storage class for the hive-metastore-db-data persistent volume claim, specify the storage class in your MeteringConfig custom resource. An example storage section with the class field is included in the metastore-storage.yaml file below.
- 1
- Uncomment this line and replace
nullwith the name of the storage class to use. Leaving the valuenullwill cause metering to use the default storage class for the cluster.
4.4.1.2. Configuring the volume size for the Hive metastore Link kopierenLink in die Zwischenablage kopiert!
Use the metastore-storage.yaml file below as a template to configure the volume size for the Hive metastore.
- 1
- Replace the value for
sizewith your desired capacity. The example file shows "5Gi".
4.4.2. Using MySQL or PostgreSQL for the Hive metastore Link kopierenLink in die Zwischenablage kopiert!
The default installation of metering configures Hive to use an embedded Java database called Derby. This is unsuited for larger environments and can be replaced with either a MySQL or PostgreSQL database. Use the following example configuration files if your deployment requires a MySQL or PostgreSQL database for Hive.
There are three configuration options you can use to control the database that is used by Hive metastore: url, driver, and secretName.
Create your MySQL or Postgres instance with a user name and password. Then create a secret by using the OpenShift CLI (oc) or a YAML file. The secretName you create for this secret must map to the spec.hive.spec.config.db.secretName field in the MeteringConfig object resource.
Procedure
Create a secret using the OpenShift CLI (
oc) or by using a YAML file:Create a secret by using the following command:
oc --namespace openshift-metering create secret generic <YOUR_SECRETNAME> --from-literal=username=<YOUR_DATABASE_USERNAME> --from-literal=password=<YOUR_DATABASE_PASSWORD>
$ oc --namespace openshift-metering create secret generic <YOUR_SECRETNAME> --from-literal=username=<YOUR_DATABASE_USERNAME> --from-literal=password=<YOUR_DATABASE_PASSWORD>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a secret by using a YAML file. For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Create a configuration file to use a MySQL or PostgreSQL database for Hive:
To use a MySQL database for Hive, use the example configuration file below. Metering supports configuring the internal Hive metastore to use the MySQL server versions 5.6, 5.7, and 8.0.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteWhen configuring Metering to work with older MySQL server versions, such as 5.6 or 5.7, you might need to add the
enabledTLSProtocolsJDBC URL parameter when configuring the internal Hive metastore.You can pass additional JDBC parameters using the
spec.hive.config.url. For more details, see the MySQL Connector/J 8.0 documentation.To use a PostgreSQL database for Hive, use the example configuration file below:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can pass additional JDBC parameters using the
spec.hive.config.url. For more details, see the PostgreSQL JDBC driver documentation.
4.5. Configuring the Reporting Operator Link kopierenLink in die Zwischenablage kopiert!
Metering is a deprecated feature. Deprecated functionality is still included in OpenShift Container Platform and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.
For the most recent list of major functionality that has been deprecated or removed within OpenShift Container Platform, refer to the Deprecated and removed features section of the OpenShift Container Platform release notes.
The Reporting Operator is responsible for collecting data from Prometheus, storing the metrics in Presto, running report queries against Presto, and exposing their results via an HTTP API. Configuring the Reporting Operator is primarily done in your MeteringConfig custom resource.
4.5.1. Securing a Prometheus connection Link kopierenLink in die Zwischenablage kopiert!
When you install metering on OpenShift Container Platform, Prometheus is available at https://prometheus-k8s.openshift-monitoring.svc:9091/.
To secure the connection to Prometheus, the default metering installation uses the OpenShift Container Platform certificate authority (CA). If your Prometheus instance uses a different CA, you can inject the CA through a config map. You can also configure the Reporting Operator to use a specified bearer token to authenticate with Prometheus.
Procedure
Inject the CA that your Prometheus instance uses through a config map. For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, to use the system certificate authorities for publicly valid certificates, set both
useServiceAccountCAandconfigMap.enabledtofalse.- Specify a bearer token to authenticate with Prometheus. For example:
4.5.2. Exposing the reporting API Link kopierenLink in die Zwischenablage kopiert!
On OpenShift Container Platform the default metering installation automatically exposes a route, making the reporting API available. This provides the following features:
- Automatic DNS
- Automatic TLS based on the cluster CA
Also, the default installation makes it possible to use the OpenShift Container Platform service for serving certificates to protect the reporting API with TLS. The OpenShift Container Platform OAuth proxy is deployed as a sidecar container for the Reporting Operator, which protects the reporting API with authentication.
4.5.2.1. Using OpenShift Container Platform Authentication Link kopierenLink in die Zwischenablage kopiert!
By default, the reporting API is secured with TLS and authentication. This is done by configuring the Reporting Operator to deploy a pod containing both the Reporting Operator’s container, and a sidecar container running OpenShift Container Platform auth-proxy.
To access the reporting API, the Metering Operator exposes a route. After that route has been installed, you can run the following command to get the route’s hostname.
METERING_ROUTE_HOSTNAME=$(oc -n openshift-metering get routes metering -o json | jq -r '.status.ingress[].host')
$ METERING_ROUTE_HOSTNAME=$(oc -n openshift-metering get routes metering -o json | jq -r '.status.ingress[].host')
Next, set up authentication using either a service account token or basic authentication with a username and password.
4.5.2.1.1. Authenticate using a service account token Link kopierenLink in die Zwischenablage kopiert!
With this method, you use the token in the Reporting Operator’s service account, and pass that bearer token to the Authorization header in the following command:
TOKEN=$(oc -n openshift-metering serviceaccounts get-token reporting-operator)
$ TOKEN=$(oc -n openshift-metering serviceaccounts get-token reporting-operator)
curl -H "Authorization: Bearer $TOKEN" -k "https://$METERING_ROUTE_HOSTNAME/api/v1/reports/get?name=[Report Name]&namespace=openshift-metering&format=[Format]"
Be sure to replace the name=[Report Name] and format=[Format] parameters in the URL above. The format parameter can be json, csv, or tabular.
4.5.2.1.2. Authenticate using a username and password Link kopierenLink in die Zwischenablage kopiert!
Metering supports configuring basic authentication using a username and password combination, which is specified in the contents of an htpasswd file. By default, a secret containing empty htpasswd data is created. You can, however, configure the reporting-operator.spec.authProxy.htpasswd.data and reporting-operator.spec.authProxy.htpasswd.createSecret keys to use this method.
Once you have specified the above in your MeteringConfig resource, you can run the following command:
curl -u testuser:password123 -k "https://$METERING_ROUTE_HOSTNAME/api/v1/reports/get?name=[Report Name]&namespace=openshift-metering&format=[Format]"
$ curl -u testuser:password123 -k "https://$METERING_ROUTE_HOSTNAME/api/v1/reports/get?name=[Report Name]&namespace=openshift-metering&format=[Format]"
Be sure to replace testuser:password123 with a valid username and password combination.
4.5.2.2. Manually Configuring Authentication Link kopierenLink in die Zwischenablage kopiert!
To manually configure, or disable OAuth in the Reporting Operator, you must set spec.tls.enabled: false in your MeteringConfig resource.
This also disables all TLS and authentication between the Reporting Operator, Presto, and Hive. You would need to manually configure these resources yourself.
Authentication can be enabled by configuring the following options. Enabling authentication configures the Reporting Operator pod to run the OpenShift Container Platform auth-proxy as a sidecar container in the pod. This adjusts the ports so that the reporting API isn’t exposed directly, but instead is proxied to via the auth-proxy sidecar container.
-
reporting-operator.spec.authProxy.enabled -
reporting-operator.spec.authProxy.cookie.createSecret -
reporting-operator.spec.authProxy.cookie.seed
You need to set reporting-operator.spec.authProxy.enabled and reporting-operator.spec.authProxy.cookie.createSecret to true and reporting-operator.spec.authProxy.cookie.seed to a 32-character random string.
You can generate a 32-character random string using the following command.
openssl rand -base64 32 | head -c32; echo.
$ openssl rand -base64 32 | head -c32; echo.
4.5.2.2.1. Token authentication Link kopierenLink in die Zwischenablage kopiert!
When the following options are set to true, authentication using a bearer token is enabled for the reporting REST API. Bearer tokens can come from service accounts or users.
-
reporting-operator.spec.authProxy.subjectAccessReview.enabled -
reporting-operator.spec.authProxy.delegateURLs.enabled
When authentication is enabled, the Bearer token used to query the reporting API of the user or service account must be granted access using one of the following roles:
- report-exporter
- reporting-admin
- reporting-viewer
- metering-admin
- metering-viewer
The Metering Operator is capable of creating role bindings for you, granting these permissions by specifying a list of subjects in the spec.permissions section. For an example, see the following advanced-auth.yaml example configuration.
Alternatively, you can use any role which has rules granting get permissions to reports/export. This means get access to the export sub-resource of the Report resources in the namespace of the Reporting Operator. For example: admin and cluster-admin.
By default, the Reporting Operator and Metering Operator service accounts both have these permissions, and their tokens can be used for authentication.
4.5.2.2.2. Basic authentication with a username and password Link kopierenLink in die Zwischenablage kopiert!
For basic authentication you can supply a username and password in the reporting-operator.spec.authProxy.htpasswd.data field. The username and password must be the same format as those found in an htpasswd file. When set, you can use HTTP basic authentication to provide your username and password that has a corresponding entry in the htpasswdData contents.
4.6. Configure AWS billing correlation Link kopierenLink in die Zwischenablage kopiert!
Metering is a deprecated feature. Deprecated functionality is still included in OpenShift Container Platform and continues to be supported; however, it will be removed in a future release of this product and is not recommended for new deployments.
For the most recent list of major functionality that has been deprecated or removed within OpenShift Container Platform, refer to the Deprecated and removed features section of the OpenShift Container Platform release notes.
Metering can correlate cluster usage information with AWS detailed billing information, attaching a dollar amount to resource usage. For clusters running in EC2, you can enable this by modifying the example aws-billing.yaml file below.
To enable AWS billing correlation, first ensure the AWS Cost and Usage Reports are enabled. For more information, see Turning on the AWS Cost and Usage Report in the AWS documentation.
- 1
- Update the bucket, prefix, and region to the location of your AWS Detailed billing report.
- 2 3 4
- All
secretNamefields should be set to the name of a secret in the metering namespace containing AWS credentials in thedata.aws-access-key-idanddata.aws-secret-access-keyfields. See the example secret file below for more details.
To store data in S3, the aws-access-key-id and aws-secret-access-key credentials must have read and write access to the bucket. For an example of an IAM policy granting the required permissions, see the aws/read-write.json file below.
This can be done either pre-installation or post-installation. Disabling it post-installation can cause errors in the Reporting Operator.