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.
Let’s walk through the installation of Kubecost step by step.
To use Kubecost, you’ll need:
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.
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.
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
For production use, where highly available volumes and automatic node-failure recovery are important, more reliable solutions than Local Path Provisioner are preferred. One such option is S3 storage from Hostman. You can easily install the CSI S3 addon.
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.
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.
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
.
Note: The Kubecost UI may vary by version; button labels, metrics, and other elements may change.
Go to the Settings tab (on the left, might be hidden) for initial configuration.
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.
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.
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
.
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. |
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.
Error |
Symptoms |
Solution |
Out of memory |
|
Add new worker nodes via Hostman (Resources tab). Kubernetes will reschedule the pods. |
Lack of CPU or disk |
Pods stuck in |
Add more resources, check Prometheus logs for retention or WAL errors. |
Prometheus out of disk space |
Logs show |
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 |
No PersistentVolume for PVC |
Error: |
Refer to Step One, reinstall Kubecost with proper storage. |
PVC stuck in Pending |
|
Ensure storage class exists or set manually. |
Missing metrics in UI |
No data/graphs; logs show |
Verify Prometheus is running and has enough disk. |
Helm install fails |
Errors like |
Retry Step Two, ensure you have proper RBAC permissions. |
UI inaccessible via port |
Port-forward runs, but |
Use |
Zero dollar cost in UI |
Cost Allocation shows $0 or no data |
Manually define the cost model under Settings > On-Prem. |
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.