Skip to content

Kubecost

Kubecost provides real-time cost visibility and insights by uncovering patterns that create overspending on infrastructure to help teams prioritize where to focus optimization efforts. By identifying root causes for negative patterns, customers using Kubecost save 30-50% or more of their Kubernetes cloud infrastructure costs.

Intro

Today, Kubecost empowers more than 2,000 teams across companies of all sizes to monitor and reduce costs, while balancing cost, performance, and reliability. Kubecost is tightly integrated with the open source cloud native ecosystem and built for engineers and developers first, making it easy to drive adoption within your organization.

This recipe describes how customers can standardize the configuration, deployment and lifecycle management of the Open Source version of Kubecost across their fleet of clusters.


What Will You Do

In this exercise,

  • You will create a customized "kubecost" add-on using Kubecost's "official Helm chart"
  • You will use the add-on in a custom cluster blueprint
  • You will then apply this cluster blueprint to a managed cluster

Important

This recipe describes the steps to create and use a custom cluster blueprint using the Web Console. The entire workflow can also be fully automated and embedded into an automation pipeline.


Assumptions

  • You have already provisioned or imported one or more Kubernetes clusters using the controller.

Step 1: Create Repository

We will be using the Kubecost Helm chart from the official GitHub repository. This repository will contain the latest version. In this example, we will be using the latest Kubecost version as of the date of this article, v1.87.3.

  • Under Integrations, select "Repositories" and create a new repository named "kubecost" of type "Helm"
  • Click "Create"

Create Repository

Create Repository


Step 2: Customize Values

The Kubecost Helm chart comes with a very detailed values.yaml file with support for a large number of scenarios. We will be customizing the defaults with our own override "values.yaml"

Copy the details below into a file named "kubecost-custom-values.yaml".

  • Replace the "kubecostToken" value with your Kubecost token.

Note

Reference on how to get the Kubecost token can be found here

## Custom values for kubecost
reporting:
  valuesReporting: false
## Change to your kubecost token below. Instructions on how to obtain the token can be found here https://www.kubecost.com/install#show-instructions
kubecostToken: "XXX"

Step 3: Create Namespace

  • Login into the Web Console and navigate to your Project as an Org Admin or Infrastructure Admin
  • Under Infrastructure, select "Namespaces" and create a new namespace called "kubecost" and select type "Wizard"

Create Namespace

  • Click "Save & Go to Placement"

Create Namespace

  • Select the cluster/s that the namespace will be added to. Select "Save & Go To Publish"

Create Namespace

  • Click "Publish" to publish the namespace to the selected cluster/s

Create Namespace

  • Once the namespace has been published, Click "Exit"

Create Namespace

  • Under Infrastructure, select "Clusters". Click on the "Kubectl" button on the cluster to open a virtual terminal
  • Verify if the "kubecost" namespace has been created by running the below command
kubectl get ns kubecost

NAME            STATUS   AGE
kubecost        Active   44m

Step 4: Create Add-on

From the Web Console: - Select "Add-ons" and "Create" a new Add-on called "kubecost" - Select "Bring your own" - Select "Helm 3" for type - Select "Pull files from repository" - Select "Helm" for the repository type - Select "kubecost" for the namespace - Click on "Create"

Create Addon

  • Create a new version of the add-on
  • Select "New Version"
  • Provide a version name such as "v1"
  • Select "kubecost" for the repository
  • Enter "cost-analyzer" for the chart name
  • Upload the "kubecost-custom-values.yaml" file that was previously created
  • Click "Save Changes"

Create Addon


Step 5: Create Blueprint

Now, we are ready to assemble a custom cluster blueprint using the newly created Kubecost add-on. You can add other add-ons to the same custom blueprint.

  • Under Infrastructure, select "Blueprints"
  • Create a new blueprint and give it a name such as "kubecost"
  • Click "Save"

Create Blueprint

  • Create a new version of the blueprint
  • Select "New Version"
  • Provide a version name such as "v1"
  • Under Add-Ons, select the "kubecost" add-on and the version that was previously created
  • Click "Save Changes"

Create Blueprint


Step 6: Apply Blueprint

Now, we are ready to apply this custom blueprint to a cluster.

  • Click on Options for the target Cluster in the Web Console
  • Select "Update Blueprint" and select the "kubecost" blueprint and version we created previously
  • Click on "Save and Publish".

Update Blueprint

This will start the deployment of the add-ons configured in the "kubecost" blueprint to the targeted cluster. The blueprint sync process can take a few minutes. Once complete, the cluster will display the current cluster blueprint details and whether the sync was successful or not.


Step 7: Verify Deployment

Users can optionally verify whether the correct resources have been created on the cluster. Click on the Kubectl button on the cluster to open a virtual terminal

Next, we will verify the pods in the "kubecost" namespace. You should see something like the example below.

kubectl get pod -n kubecost

NAME                                          READY   STATUS    RESTARTS   AGE
kubecost-cost-analyzer-8544c4bbd4-gx4nl       3/3     Running   0          6m23s
kubecost-grafana-768655466d-vlsmq             3/3     Running   0          6m23s
kubecost-kube-state-metrics-f99c657b5-mh5mt   1/1     Running   0          6m23s
kubecost-prometheus-node-exporter-26fwv       1/1     Running   0          6m23s
kubecost-prometheus-node-exporter-zfkvw       1/1     Running   0          6m23s
kubecost-prometheus-server-5cc6745978-z98f8   2/2     Running   0          6m23s

Step 8: Enable Port-Forward

In order to access the Kubecost interface, we will need to enable access to the frontend application using port-forward. To do this, we will download and use the Kubeconfig with the KubeCTL CLI (../../accessproxy/kubectl_cli/)

kubectl port-forward --namespace kubecost deployment/kubecost-cost-analyzer 9090

Forwarding from 127.0.0.1:9090 -> 9090
Forwarding from [::1]:9090 -> 9090
Handling connection for 9090

Step 9: View Data

You can now access the Kubecost interface by visiting the following link. http://localhost:9090

kubecost Dashboards


Recap

Congratulations! You have successfully created a custom cluster blueprint with the "kubecost" add-on and applied to a cluster. You can now use this blueprint on as many clusters as you require.