Manage GCP costs by using CCM on Harness Self-Managed Enterprise Edition
This topic walks you through the steps required to set up CCM for GCP in a self-managed platform.
Figure: GCP CCM Self-Managed Enterprise Edition architecture diagram
Major Components
- K8s Job: In the cloud-hosted infra, a K8s Job is configured to run daily. This job performs all necessary steps to ingest GCP billing data from BigQuery to ClickHouse, utilizing a GCS bucket as an intermediary and then eventually to ClickHouse table.
- BigQuery: The GCP project's billing data resides in a BigQuery table.
- Google Cloud Storage (GCS): Billing data is stored in the parquet format in GCS bucket. Parquet, as a column-oriented format, represents a better interchange format since it is inherently compressed and faster for BigQuery to export and ClickHouse to query.
- ClickHouse: Serves as the datastore where GCP billing data is finally ingested.
- Service Account Key: It is a JSON file that contains the information needed to authenticate and authorize requests made by an application or a service.
- HMAC Key: HMAC (Hash-based Message Authentication Code) keys are used for authentication and ensuring the integrity of requests made to GCS.
Data Flow
Steps
- Authenticate and initialize clients for BigQuery, GCS and ClickHouse using SA and HMAC keys.
- Create a dedicated GCS bucket to store billing data in Parquet format. The sub-folders will be organized based on timestamps or dates to precisely track when each bucket was created.
- Initiate an export query to transfer data from BigQuery to the GCS bucket in Parquet format with GZIP compression. The export query employs a SELECT statement, resulting in charges based solely on the data scan.
- Check if the billing table exists in ClickHouse; create it if not.
- Initiate an insert query to efficiently move data from the GCS bucket to the ClickHouse table in batch.
You need to perform the following tasks to set up CCM for GCP:
- Create Service Account
- Create HMAC Key
- Deploying workloads via Helm Charts
- Handling Kubernetes Secrets
GCP Setup
Step 1: Create Service Account
A GCP service account is needed to be able to authenticate and perform operations on the customer’s BQ and GCS buckets.You will need one SA and its JSON key during onboarding.
- Before creating a Service Account, you have to create Custom Role and provide necessary permissions to it. Follow these steps to create Custom Role and add below permissions:
bigquery.datasets.create
bigquery.datasets.get
bigquery.datasets.getIamPolicy
bigquery.jobs.create
bigquery.tables.create
bigquery.tables.export
bigquery.tables.get
bigquery.tables.getData
bigquery.tables.list
storage.buckets.create
storage.buckets.get
storage.objects.list
storage.objects.create
storage.objects.get
- Follow these steps to create Service Account and add the above IAM custom role to it.
- Follow these steps to create Service Account Credential Key.
Please refer this doc if you encounter any difficulties understanding the process. It provides a comprehensive explanation of all steps accompanied by screenshots.