Installing Kubecost with Rafay

Rafay is a SaaS-first Kubernetes Operations Platform (KOP) with enterprise-class scalability, zero-trust security and interoperability for managing applications across public clouds, data centers & edge.

See Rafay documentation to learn more about the platform and how to use it.

This document will walk you through installing Kubecost on a cluster that has been provisioned or imported using the Rafay controller. The steps below describe how to create and use a custom cluster blueprint via the Rafay Web Console. The entire workflow can also be fully automated and embedded into an automation pipeline using the RCTL CLI utility or Rafay REST APIs.

Prerequisites

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

Step 1: Create a repository

Under Integrations:

  • Select Repositories and create a new repository named kubecost of type Helm.

  • Select Create.

  • Enter the endpoint value of https://kubecost.github.io/cost-analyzer/.

  • Select Save.

Step 2: Customize values

You'll need to override the default values.yaml file. Create a new file called kubecost-custom-values.yaml with the following content:

# Custom values for Kubecost
reporting:
  valuesReporting: false
# Replace token with the value you get from kubecost.com/install
# after entering your email address
kubecostToken: 'token_string'

Step 3: Create a namespace

  • Login to the Rafay 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.

  • Select Save & Go to Placement.

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

  • Select Publish to publish the namespace to the selected cluster(s).

  • Once the namespace has been published, select Exit.

  • Under Infrastructure, select Clusters.

  • Select the kubectl button on the cluster to open a virtual terminal.

  • Verify that the kubecost namespace has been created by running the following command:

$ kubectl get ns kubecost

NAME            STATUS   AGE
kubecost        Active   44m

Step 4: Create an 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.

  • Select Select.

  • 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.

  • Select Save Changes.

Step 5: Create a blueprint

Once you've created the Kubecost add-on, use it in assembling a custom cluster blueprint. 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.

  • Select Save.

  • 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.

  • Select Save Changes.

Step 6: Apply blueprint

You may now apply this custom blueprint to a cluster.

  • Select Options for the target cluster in the Web Console.

  • Select Update Blueprint and select the kubecost blueprint and version you created previously.

  • Select Save and Publish.

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

You can optionally verify whether the correct resources have been created on the cluster. Select the kubectl button on the cluster to open a virtual terminal.

Then, verify the pods in the kubecost namespace. Run kubectl get pod -n kubecost, and check that the output is similar to 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 forwarding

In order to access the Kubecost UI, you'll need to enable access to the frontend application using port-forward. To do this, 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 UI by visiting http://localhost:9090 in your browser.

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

You can find Rafay's documentation on Kubecost as well as guides for how to create or import a cluster using the Rafay controller on the Rafay Product Documentation site.

Last updated