Learning Center
Kubernetes

How to Install Kubecost: Full Installation Guide

25 Jul 2025
Hostman Team
Hostman Team

Kubecost is a tool for monitoring and managing costs in Kubernetes. It helps you understand in real time how much resources (CPU, RAM, storage, etc.) each component (pod, service, namespace, deployment) is consuming, and how that translates into money. It is mainly used to monitor costs per service and optimize resource usage.

Kubecost brings cost transparency, letting you see how much each application or namespace costs. Unused resources are automatically identified.

This tool is useful for DevOps engineers in managing and optimizing resources, financial analysts in tracking infrastructure spending, and project managers in allocating costs across teams and projects.

In this article, we’ll go through the installation, integration, and initial configuration of Kubecost.

Installing Kubecost
Copy link

Let’s walk through the installation of Kubecost step by step.

Step Zero: Create and Connect to a Kubernetes Cluster
Copy link

To use Kubecost, you’ll need:

  • A Kubernetes cluster with a supported version (1.16 or newer).
  • Sufficient resources in the cluster (a minimum of 2 CPUs and 4 GB RAM is recommended for Kubecost pods).
  • A cluster management tool like kubectl.

Hostman’s cloud infrastructure provides the ability to create a Kubernetes cluster with a recommended configuration (2 CPUs @ 3.3 GHz, 4 GB RAM, 60 GB NVMe).

We described the process of creating a cluster in the documentation. For easier monitoring, you can also install the Kubernetes Dashboard with a single click.

Once the cluster is created, connect to it—we recommend using Lens. The connection process is also described in detail in our docs.

You’ll need a terminal with the cluster’s context. To access it, navigate to the Overview tab in Lens and click the Terminal button located at the bottom.

All command-line operations will be performed in this terminal.

Step One: Choose a Storage Type
Copy link

Kubernetes requires dedicated storage to function properly. For development, Local Path Provisioner is a good option; for production, we recommend an external fault-tolerant storage solution.

Local Path Provisioner

This is convenient in test and local environments where a single node and low fault tolerance are sufficient. However, in clusters with multiple nodes under active testing, it may not be enough since it’s limited to local disks.

Here’s how to install it using Rancher’s ready-made manifest:

curl -s https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml | kubectl apply -f -

Expected output:

namespace/local-path-storage created
serviceaccount/local-path-provisioner-service-account created
role.rbac.authorization.k8s.io/local-path-provisioner-role created
clusterrole.rbac.authorization.k8s.io/local-path-provisioner-role created
rolebinding.rbac.authorization.k8s.io/local-path-provisioner-bind created
clusterrolebinding.rbac.authorization.k8s.io/local-path-provisioner-bind created
deployment.apps/local-path-provisioner created
storageclass.storage.k8s.io/local-path created
configmap/local-path-config created

Ensure the pod is running:

kubectl get pods -n local-path-storage

Expected output:

NAME                               READY   STATUS    RESTARTS   AGE
local-path-provisioner-xxx         1/1     Running   0          68s

After installation, a StorageClass named local-path should appear:

kubectl get sc

Expected output:

NAME         PROVISIONER              ... VOLUMEBINDINGMODE     AGE
local-path   rancher.io/local-path    ... WaitForFirstConsumer  5s

To set the created local-path as the default storage class:

kubectl patch storageclass local-path \
  -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

Expected output:

storageclass.storage.k8s.io/local-path patched

External Storage

For production use, where highly available volumes and automatic node-failure recovery are important, choose more reliable solutions than Local Path Provisioner, such as S3 storage.

Step Two: Install Kubecost
Copy link

Add the Kubecost Helm repository and update it:

helm repo add kubecost https://kubecost.github.io/cost-analyzer/
helm repo update

Now use one of the following Helm commands:

If the cluster has a default StorageClass:

helm install kubecost kubecost/cost-analyzer \
  --namespace kubecost --create-namespace

If the cluster does NOT have a default StorageClass:

helm install kubecost kubecost/cost-analyzer \
  --namespace kubecost --create-namespace \
  --set global.storageClass=<STORAGECLASS>

Expected output:

Kubecost 2.x.x has been successfully installed.

Step Three: Verify Installation
Copy link

Check that the PersistentVolumeClaims (PVCs) created by Kubecost are in Bound status:

kubectl get pvc -n kubecost

Expected output (trimmed for clarity):

NAME                         STATUS
kubecost-cost-analyzer       Bound
kubecost-prometheus-server   Bound

Make sure each PVC shows Bound.

Next, ensure all pods are running and error-free:

kubectl get pod -n kubecost

Expected output:

NAME                              READY   STATUS    RESTARTS
kubecost-cost-analyzer-xxx        4/4     Running   0
kubecost-forecasting-xxx          1/1     Running   0
kubecost-grafana-xxx              2/2     Running   0
kubecost-prometheus-server-xxx    1/1     Running   0

If you see this, Kubecost is installed correctly.

Step Four: Port Forwarding
Copy link

To manage Kubecost and view its metrics, you need to port-forward to your local machine.

First, identify the service used by Kubecost:

kubectl get svc -n kubecost

Expected output (trimmed):

NAME                       TYPE        CLUSTER-IP        EXTERNAL-IP   PORT
kubecost-cost-analyzer     ClusterIP   10.111.138.113    <none>        9090/TCP

The desired service is typically kubecost-cost-analyzer, and its port is 9090. Forward it:

kubectl port-forward -n kubecost service/kubecost-cost-analyzer 9090:9090

Expected output:

Forwarding from 127.0.0.1:9090 -> 9090
Forwarding from [::1]:9090 -> 9090

Now you can use Kubecost via the web UI at http://localhost:9090.

How to Configure Kubecost
Copy link

Go to the Settings tab (on the left, might be hidden) for initial configuration.

Cost Model Configuration
Copy link

Filling out this section is recommended for accurate cost calculations.

Scroll to the Pricing section and enable the Enable Custom Pricing toggle. The app will prompt you to enter resource pricing manually.

If using Hostman, you can find this pricing info on the Create Cluster page, under section 3. Worker Nodes Configuration, tab Custom. There, sliders will display the cost of the selected configuration.

Note: In Hostman, the cost of fixed-configuration worker nodes is lower than that of equivalent custom-configured ones.

Example field entry:

Field

Value

Description

Monthly CPU Price

$1.80

Price per 1 vCPU

Monthly Spot CPU Price*

0

Price per 1 Spot vCPU

Monthly RAM Price

$1.50

Price per 1 GB of RAM

Monthly Spot RAM Price*

0

Price per 1 GB of Spot RAM

Monthly GPU Price*

0

Price per 1 GPU

Monthly Storage Price

$0.04

Price per 1 GB of storage

* — Not used in Hostman.

Custom Labels
Copy link

Labels are used to identify, group, and detail costs associated with Kubernetes resources.

Scroll to the Labels section. It’s similar in layout to the cost model section.

Name

Description

Default Value

Owner Label / Annotation

Indicates resource owner (e.g., user or team)*

owner

Team Label

Defines the team using the resource*

team

Department Label

Links the resource to a department or cost center*

department

Product Label

Specifies the app/product the resource is for*

app

Environment Label

Indicates the environment (dev, prod, staging, etc.)

env

GPU Label

Node-level label indicating GPU type

GPU Label Value

Label value indicating GPU presence

* — supports CSV format.

Prometheus Status Check
Copy link

Kubecost retrieves metrics from Prometheus.

Scroll down to Prometheus Status—it’s near the bottom of the Settings page. You should see green checkmarks for each metric (as shown in the screenshot).

If metrics are missing, Kubecost may not work as expected.

For full diagnostics, visit: http://localhost:9090/diagnostics.

Alert Configuration
Copy link

Kubecost can notify users of unexpected events. Alerts can be sent via email, Slack, webhooks, or Microsoft Teams.

Go to the Alerts tab. Under Global Recipients, enter the contacts for global alert delivery.

Below that, you can define alert types and specific recipients. Each type is described below:

Name

Description

Allocation Budget

Budget for cost allocation at namespace/team/project level. Notifies on overage.

Allocation Efficiency

Resource usage efficiency (e.g., CPU, RAM) within budgets or namespaces.

Allocation Recurring Update

Regular updates on resource allocation and costs.

Allocation Spend Change

Notifies of significant changes in resource spend.

Asset Budget

Budget for physical/virtual resources (nodes, GPUs, disks). Alerts on overage.

Asset Recurring Update

Regular updates on physical/virtual resource usage.

Cloud Cost Budget

Budget for cloud costs. Alerts when exceeded.

Uninstalling and Reinstalling Kubecost
Copy link

Sometimes, full uninstallation is required to fix issues—for example, if no default StorageClass was set during the initial install.

To remove Kubecost completely:

helm uninstall kubecost -n kubecost
kubectl delete ns kubecost

To reinstall, follow Step Two again.

Troubleshooting Common Issues
Copy link

Error

Symptoms

Solution

Out of memory

OOMKilled, logs show CrashLoopBackOff

Add new worker nodes via Hostman (Resources tab). Kubernetes will reschedule the pods.

Lack of CPU or disk

Pods stuck in CrashLoopBackOff; Prometheus shows incomplete data

Add more resources, check Prometheus logs for retention or WAL errors.

Prometheus out of disk space

Logs show Storage retention limit reached, WAL write errors

Resize disk (for external storage), or add a new disk and migrate Prometheus data (local).

UI slow / Graphs timing out

Graphs load slowly or timeout

Increase resources.requests/limits; optimize Prometheus retention and use recording rules.

No PersistentVolume for PVC

Error: 0/2 nodes ... no available persistent volumes to bind

Refer to Step One, reinstall Kubecost with proper storage.

PVC stuck in Pending

kubectl get pvc shows Pending; no PV or no StorageClass

Ensure storage class exists or set manually.

Missing metrics in UI

No data/graphs; logs show Unable to query Prometheus

Verify Prometheus is running and has enough disk.

Helm install fails

Errors like chart not found, or failed resource creation

Retry Step Two, ensure you have proper RBAC permissions.

UI inaccessible via port

Port-forward runs, but http://<node_ip>:9090 fails

Use http://localhost:9090 if running locally; configure NodePort or LoadBalancer access.

Zero dollar cost in UI

Cost Allocation shows $0 or no data

Manually define the cost model under Settings > On-Prem.

Conclusion
Copy link

Kubecost is a powerful tool for monitoring and optimizing Kubernetes costs. It helps make infrastructure spending transparent and manageable. This guide covered the full installation and configuration process, including cluster preparation, choosing a storage class, Helm-based deployment, cost model setup, and Prometheus integration.

Effective use of Kubecost not only helps reduce expenses but also improves resource management across teams, projects, and applications. By following this guide, you’ll be able to deploy and tailor Kubecost to suit your infrastructure needs.