What is OpenCost?

Grigor Khachatryan
3 min readDec 12, 2022

--

https://github.com/opencost/opencost/blob/develop/opencost-header.png

OpenCost is an open-source cost monitoring tool for Kubernetes environments. It is designed to help organizations monitor and manage the cost of running their applications in Kubernetes, and to identify opportunities for cost savings.

One of the key features of OpenCost is its ability to provide detailed cost breakdowns for individual applications and components. It can show the costs associated with each container, pod, service, and deployment, and can highlight areas where costs are higher than expected. This can help users identify opportunities for cost savings, such as by optimizing resource usage or by scaling applications up or down as needed.

OpenCost also provides a range of other useful features, such as the ability to monitor the cost of different environments, such as development, staging, and production, and to compare costs across environments. It also provides alerts and notifications when costs exceed specified thresholds, and allows users to create custom dashboards and reports to track and analyze their costs over time.

https://github.com/opencost/opencost/blob/develop/ui/src/opencost-ui.png

One of the key benefits of using OpenCost is that it provides real-time visibility into the cost of running applications in Kubernetes. This can be particularly valuable for organizations with large or complex Kubernetes environments, where it can be difficult to understand and manage costs across different applications, teams, and departments. By providing detailed cost breakdowns and analysis tools, OpenCost can help users to identify opportunities for cost savings and make more informed decisions about how to manage their costs.

In addition, OpenCost supports a range of different cloud providers, including AWS, Azure, and GCP. This means that it can be used to monitor and manage costs across multiple cloud platforms, providing a comprehensive view of an organization's cloud spending. It also supports on-premises Kubernetes clusters, which is useful for organizations that are running their own Kubernetes environments.

To see the full functionality of OpenCost you can view OpenCost features. Here is a summary of features enabled:

  • Real-time cost allocation by Kubernetes cluster, node, namespace, controller kind, controller, service, or pod
  • Dynamic onDemand asset pricing enabled by integrations with AWS, Azure, and GCP billing APIs
  • Supports on-prem k8s clusters with custom CSV pricing
  • Allocation for in-cluster resources like CPU, GPU, memory, and persistent volumes.
  • Easily export pricing data to Prometheus with /metrics endpoint
  • Free and open source distribution (Apache2 license)

Quick Start Installation

To get started with OpenCost, the first step is to install the tool in the Kubernetes environment. This can be done using the Helm package manager, which makes it easier to manage and deploy applications in Kubernetes environments. The following command can be used to install the Prometheus chart from the Prometheus community Helm repository and set up OpenCost in the Kubernetes environment:

helm install my-prometheus --repo https://prometheus-community.github.io/helm-charts prometheus \
--namespace prometheus --create-namespace \
--set pushgateway.enabled=false \
--set alertmanager.enabled=false \
-f https://raw.githubusercontent.com/opencost/opencost/develop/kubernetes/prometheus/extraScrapeConfigs.yaml

kubectl apply --namespace opencost -f https://raw.githubusercontent.com/opencost/opencost/develop/kubernetes/opencost.yaml

Testing

Run this port-forward command:

kubectl port-forward --namespace opencost service/opencost 9003

To test that the server is running, you can hit http://localhost:9003/allocation/compute?window=60m

Or use kubectl cost:

kubectl cost --service-port 9003 --service-name opencost --kubecost-namespace opencost --allocation-path /allocation/compute  \
namespace \
--window 5m \
--show-efficiency=true

Output:

+---------+---------------+--------------------+-----------------+
| CLUSTER | NAMESPACE | MONTHLY RATE (ALL) | COST EFFICIENCY |
+---------+---------------+--------------------+-----------------+
| | opencost | 18.295200 | 0.231010 |
| | prometheus | 17.992800 | 0.000000 |
| | kube-system | 11.383200 | 0.033410 |
+---------+---------------+--------------------+-----------------+
| SUMMED | | 47.671200 | |
+---------+---------------+--------------------+-----------------+

Deleting OpenCost

To delete OpenCost, enter the following command:

kubectl delete -f https://raw.githubusercontent.com/opencost/opencost/develop/kubernetes/opencost.yaml

Like to learn?

Follow me on twitter where I post all about the latest and greatest AI, DevOps, VR/AR, Technology, and Science! Connect with me on LinkedIn too!

--

--

No responses yet