This feature is only supported for Kubecost Enterprise.
The Postgres Integration feature enables users to periodically query and export their Kubecost data to a central Postgres database.
Example use cases
Customized dashboarding used by FinOps/Analytics teams.
Single view populated by multiple data sources, to be used by developer/finance/operations teams.
Customized budgeting and forecasting via an in-house data pipeline.
Usage
Prerequisites:
A running Postgres instance that is reachable by Kubecost.
Credentials for a Postgres user which has CREATE, INSERT, and UPDATE permissions on the database.
Step 1: Configure Helm values
The below YAML is an example of how to configure the Postgres integration in your Helm values file. Notice that there are four different queries being created (2 allocation queries, 1 asset query, 1 cloudCost query). Each query is configured to run every 12h and write to their respective tables in the Postgres database.
global:integrations:postgres:enabled:truerunInterval:"12h"# How frequently to run the integration.databaseHost:""# REQUIRED. ex: my.postgres.database.azure.comdatabasePort:""# REQUIRED. ex: 5432databaseName:""# REQUIRED. ex: postgresdatabaseUser:""# REQUIRED. ex: myusernamedatabasePassword:""# REQUIRED. ex: mypassword databaseSecretName: "" # OPTIONAL. Specify your own k8s secret containing the above credentials. Must have key "creds.json".
queryConfigs:allocations: - databaseTable:"kubecost_allocation_data"window:"7d"aggregate:"namespace"idle:"true"shareIdle:"true"shareNamespaces:"kubecost,kube-system"shareLabels:"" - databaseTable:"kubecost_allocation_data_by_cluster"window:"10d"aggregate:"cluster"idle:"true"shareIdle:"false"shareNamespaces:""shareLabels:""assets: - databaseTable:"kubecost_assets_data"window:"7d"aggregate:"cluster"cloudCosts: - databaseTable:"kubecost_cloudcosts_data"window:"7d"aggregate:"service"# REQUIRED. Aggregator must be enabled and running as a statefulset.kubecostAggregator:deployMethod:"statefulset"kubecostModel:federatedStorageConfigSecret:"federated-store"prometheus:server:global:external_labels:cluster_id:"primary-cluster-1"# REQUIRED. A Kubecost Enterprise license key.kubecostProductConfigs:productKey:enabled:truekey:"my-enterprise-key-here"
Multiple inserts into the database per day will not create duplicate data. All queries to the database are keyed on a unique name, windowStart, and windowEnd. If a key already exists in the database, we update the entry with the new data.
You can also specify a Kubernetes secret containing the database credentials via databaseSecretName. Below is an example of what the secret should look like.
Once you've applied your changes, validate that the integration is successful by checking the Aggregator pod logs. You should see logs similar to the following: