Integrating Kubecost with Datadog
Datadog is a monitoring and security platform which teams use for cloud applications or cloud monitoring as a service. It is possible to integrate your installed Kubecost with Datadog to receive real-time cost monitoring and visualization in your Datadog dashboard. This article will show you everything you need to do this.
Before you get started, you will need the following:
When installing your Datadog agent, you need to enable the following flags to allow the Datadog agent to collect the metrics from Kubecost’s cost-model container:
To do this, start by setting up your Datadog API key as an environment variable. You can get the API key after logging into your Datadog account by selecting your account > Organization Settings > API Keys. The value of
DATADOG_API_KEYbelow can be found by selecting the line item and copying your API key (do not use the value in the Key ID column).
Finally, install the Datadog agent with your API key using the following command:
helm repo add datadog https://helm.datadoghq.com
helm upgrade -i datadog-agent datadog/datadog \
--set --set datadog.site='us5.datadoghq.com' \
--set datadog.apiKey=$<DATADOG_KEY_ID> \
--set datadog.prometheusScrape.enabled=‘true’ \
Install Kubecost using the following command to allow the Datadog agent to collect the metrics:
helm upgrade --install kubecost --namespace kubecost --create-namespace \
--repo https://kubecost.github.io/cost-analyzer/ cost-analyzer \
-f https://raw.githubusercontent.com/kubecost/poc-common-configurations/main/datadog/datadog-values.yaml \
Allow 3-5 minutes to have the Kubecost installation completed, at which point the metrics are pushed into your Datadog account. Run the following command to enable port-forwarding and expose the Kubecost dashboard:
kubectl port-forward --namespace kubecost deployment/kubecost-cost-analyzer 9090
You can now access the Kubecost dashboard by navigating to
http://localhost:9090in your web browser.
Once you have verified that Kubecost metrics are pushed into your Datadog account, you can download our example Datadog dashboard
Kubecostdashboard.jsonand import it into your Datadog account to visualize the Kubecost cost allocation data. Use the following command:
In Datadog, select Dashboards in the left navigation, then select New Dashboard in the top right corner of the Dashboards page. The Create a Dashboard window opens. Create a name for your dashboard and add any relevant teams if applicable. Then, select New Dashboard.
On your dashboard, select the gear icon in the top right corner, then select Import dashboard JSON... Add the Kubecostdashboard.json file and the dashboard should automatically import. The example dashboard gives you the overview of your cluster’s monthly cost and the costs at higher levels of granularity such as containers or namespaces. See the screenshot below depicting a successful import.
Example Kubecost dashboard in Datadog