githubEdit

OpenCost

OpenCost provides visibility into current and historical Kubernetes spend and resource allocation.

Introduction

OpenCost is a CNCF sandbox project that provides real-time cost visibility and insights for Kubernetes workloads. It enables teams to understand, monitor, and optimize their Kubernetes spending at the namespace, deployment, and pod levels.

OpenCost is the open-source foundation of Kubecost, offering core cost allocation functionality without the enterprise features.

Key Features

Cost Monitoring

  • Real-time cost tracking at cluster, namespace, deployment, and pod level

  • Historical cost data with trend analysis

  • Support for AWS, GCP, Azure, and on-premises

  • Custom pricing configuration

Resource Cost Breakdown

  • CPU cost allocation

  • Memory cost allocation

  • GPU cost allocation

  • Storage (PVC) cost allocation

  • Network egress cost tracking

Multi-Cluster Support

  • Federation across multiple Kubernetes clusters

  • Unified cost reporting

  • Cluster-level comparison

Integration

  • Prometheus metrics endpoint

  • Grafana dashboard integration

  • Cloud provider APIs for accurate pricing

  • OpenTelemetry support

Architecture

OpenCost consists of:

  • Cost Model: Core calculation engine that processes Prometheus metrics

  • Allocation Service: Distributes costs across namespaces and pods

  • Prometheus Adapter: Exposes custom metrics for cost data

  • Exporter: Collects and exports cost metrics

Installation

Helm Installation

kubectl Installation

Configuration

Prometheus Configuration

OpenCost requires Prometheus. Ensure your Prometheus has the following scrape config:

Cloud Provider Integration

AWS

GCP

Azure

Accessing OpenCost

Access the UI at: http://localhost:9090

Key Metrics

Namespace Costs

Pod Costs

Cost by Service

CPU Cost

Memory Cost

GPU Cost

Storage Cost

Cost Allocation

By Namespace

OpenCost automatically allocates costs based on:

  • Resource requests

  • Resource limits

  • Actual usage

  • PVC usage

Using Labels

Cost allocation can be customized using Kubernetes labels:

Shared Costs

Configure shared costs for cluster-level resources:

Prometheus Queries

Daily Cost by Namespace

Monthly Cost Trend

Cost Efficiency Ratio

Grafana Integration

Import Dashboard

Import the official OpenCost Grafana dashboard from: https://grafana.com/dashboards/14191

Custom Queries

Alerting

Prometheus Alert Rules

ETL Pipeline

OpenCost uses an ETL (Extract, Transform, Load) pipeline for cost data:

  1. Extract: Collects data from Prometheus and cloud APIs

  2. Transform: Applies pricing models and allocations

  3. Load: Stores processed data for querying

Build ETL Pipeline

Update ETL Data

Troubleshooting

Common Issues

Missing Metrics

If metrics are missing, check:

  • Prometheus is correctly configured to scrape OpenCost

  • Prometheus has the correct role permissions

  • Network policies allow communication

Incorrect Pricing

If pricing seems wrong:

  • Verify cloud provider credentials

  • Check custom pricing configuration

  • Ensure spot data is configured (if using spot instances)

High Memory Usage

OpenCost stores historical data in Prometheus:

  • Adjust retention period

  • Configure resource limits

  • Enable downsampling for historical data

Comparison with Kubecost

Feature
OpenCost
Kubecost

Pricing Model

Open source (CNCF)

Freemium (Enterprise paid)

UI

Basic UI

Full-featured web UI

Enterprise Support

Community only

Yes

Cloud Integrations

Limited

Native

SAML/SSO

No

Yes

Multi-cluster Federation

Basic

Advanced

Custom Reporting

No

Yes

Best Practices

  1. Configure cloud integration early - Accurate pricing requires cloud provider API access

  2. Use consistent labels - Enable detailed cost allocation across teams

  3. Set up alerting - Catch cost anomalies early

  4. Review regularly - Weekly cost reviews help identify optimization opportunities

  5. Combine with right-sizing - Use cost data to right-size resources

Reference:

Last updated