Cross-cloud cost allocation models for Kubernetes workloads https://kubecost.com

Prianshu-git fda22ab9f6 Fix formatting for pricing definitions in markdown (#3461) 5 月之前
.github 75f959675d feat: Add SBOM generation workflow using Anchore SBOM Action (#3455) 5 月之前
.idea 93fbec52fb add intellij and goland gofmt settings to be consistent with vscode 3 年之前
cmd c7706a4fb2 Renamed Kubecost Github reference to OpenCost 3 年之前
configs 646ab6cb73 Add DigitalOcean Kubernetes Services provider (#3232) 8 月之前
core 9bf926c15c fix: Negative idle cost on promless mode (#3393) 6 月之前
docs 5eff933af1 docs: fix grammar and improve clarity (#3460) 5 月之前
kubernetes d13a362c72 add back scrape configs (#3433) 6 月之前
modules eba802ef15 Ingest K8s ResourceQuota metrics (#3430) 6 月之前
pkg e5e045db86 Fix JSON Casing (#3462) 5 月之前
protos c73cedb9e1 feat: Implement OpenCost Data Model v2 protobuf architecture (#3369) 7 月之前
spec fda22ab9f6 Fix formatting for pricing definitions in markdown (#3461) 5 月之前
tools 81eb9cfa29 feat(build): Add version and revision as labels 3 年之前
ui a45005f061 fix: restore missing YouTube preview thumbnail in main README (#3064) 1 年之前
.dockerignore 93dcd24356 Docker Ignore 5 年之前
.gitignore b82370afd8 OCI cloud costs integration (#2870) 1 年之前
ADOPTERS.MD 98216666ce Add Zendesk to Opencost ADOPTERS.md 2 年之前
CODE_OF_CONDUCT.md 8241f30690 Direct inquiries to Slack and the community meetings rather than Kubecost 2 年之前
CONTRIBUTING.md 87b9d14e87 Add to UI container, contributing 2 年之前
Dockerfile 8bdebf5f90 chores: Optimize Dockerfile with cross-compilation (#3351) 6 月之前
Dockerfile.cross b601a2ea98 update use of env vars, check dependabot (#3152) 1 年之前
Dockerfile.debug ea46890cef Add OTC provider (#2952) 1 年之前
GOVERNANCE.md bcaf863493 Clarifications and corrections 3 年之前
LICENSE e21bf66dc1 Add LICENSE 7 年之前
MAINTAINERS.md 59fdcb5260 welcome warwick! (#3454) 6 月之前
Makefile dec820c853 Update build for opencost 2 年之前
NOTICE 59fdcb5260 welcome warwick! (#3454) 6 月之前
PROMETHEUS.md 59fdcb5260 welcome warwick! (#3454) 6 月之前
README.md 59fdcb5260 welcome warwick! (#3454) 6 月之前
ROADMAP.md 8241f30690 Direct inquiries to Slack and the community meetings rather than Kubecost 2 年之前
SECURITY.md 59fdcb5260 welcome warwick! (#3454) 6 月之前
THIRD_PARTY_LICENSES.txt 4a9e631edc Third party attributions in opencost artifacts 2 年之前
Tiltfile 24cc2358b7 refactor and improve tilt 2 年之前
Tiltfile.opencost 37e08c6365 feat: add MCP server for OpenCost allocation and asset queries (#3386) 6 月之前
generate.sh c73cedb9e1 feat: Implement OpenCost Data Model v2 protobuf architecture (#3369) 7 月之前
go.mod 37e08c6365 feat: add MCP server for OpenCost allocation and asset queries (#3386) 6 月之前
go.sum 37e08c6365 feat: add MCP server for OpenCost allocation and asset queries (#3386) 6 月之前
justfile 81f63656e0 Add Azure Disk Sku Nil Check (#3165) 11 月之前
opencost-header.png c9a4dff062 opencost readme 4 年之前
sonar-project.properties a2c287d402 Modular Opencost (#3031) 11 月之前
tilt-values.yaml 37e08c6365 feat: add MCP server for OpenCost allocation and asset queries (#3386) 6 月之前

README.md

License OpenSSF Best Practices Gurubase

OpenCost — your favorite open source cost monitoring tool for Kubernetes and cloud spend

OpenCost give teams visibility into current and historical Kubernetes and cloud spend and resource allocation. These models provide cost transparency in Kubernetes environments that support multiple applications, teams, departments, etc. It also provides visibility into the cloud costs across multiple providers.

OpenCost was originally developed and open sourced by Kubecost. This project combines a specification as well as a Golang implementation of these detailed requirements. The web UI is available in the opencost/opencost-ui repository.

OpenCost UI Walkthrough OpenCost UI Walkthrough

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
  • Multi-cloud cost monitoring for all cloud services on AWS, Azure, GCP
  • Dynamic on-demand k8s 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 K8s resources like CPU, GPU, memory, and persistent volumes
  • Easily export pricing data to Prometheus with /metrics endpoint (learn more)
  • Carbon costs for cloud resources
  • MCP support
  • Support for external costs like Datadog through OpenCost Plugins
  • Free and open source distribution (Apache2 license)

Getting Started

OpenCost is now installed and managed via the official Helm chart only.

Quick install on any Kubernetes 1.20+ cluster:

helm repo add opencost https://opencost.github.io/opencost-helm-chart
helm repo update
helm install opencost opencost/opencost

Note: The standalone Kubernetes manifest files have been removed. Please use Helm for all installations and upgrades. See the Helm installation docs for details and configuration.

Note for sharded Prometheus users: If you run Prometheus in a sharded (HA) setup, set PROMETHEUS_SERVER_ENDPOINT to a global query endpoint (e.g., Thanos Query, Cortex, or Mimir). Pointing to a single Prometheus pod may result in incomplete or intermittent export results. See the Prometheus integration docs for details.

Usage

MCP Server

The OpenCost MCP (Model Context Protocol) server provides AI agents with access to cost allocation and asset data through a standardized interface. The MCP server is enabled by default in all OpenCost deployments, runs on port 8081, and is built into the Helm chart for easy production deployment. Users have full control to disable it or configure custom ports and settings.

Features

  • Enabled by Default: MCP server starts automatically with OpenCost
  • Full User Control: Easy to disable or configure port and settings
  • Allocation Queries: Retrieve cost allocation data with filtering and aggregation
  • Asset Queries: Access detailed asset information including nodes, disks, load balancers, and more
  • Cloud Cost Queries: Query cloud cost data with provider, service, and region filtering
  • HTTP Transport: Uses HTTP for reliable communication with MCP clients
  • Zero Configuration: Works out of the box with default OpenCost deployment
  • Helm Integration: Built into the official Helm chart for production deployments

Quick Start

Using Tilt (Development)

# Clone and start OpenCost with MCP server
git clone https://github.com/opencost/opencost.git
cd opencost
tilt up

Tilt configuration notes (cloud costs):

OpenCost's Tilt values (tilt-values.yaml) include extra environment variables to enable Cloud Cost ingestion in dev:

# tilt-values.yaml (excerpt)
opencost:
  exporter:
    extraEnv:
      CLOUD_COST_ENABLED: "true"
      CLOUD_COST_CONFIG_PATH: "/var/cloud-integration/cloud-integration.json"
  • Set CLOUD_COST_ENABLED to "true" to turn on cloud cost ingestion.
  • Point CLOUD_COST_CONFIG_PATH to the mounted cloud integration file used by Tilt (e.g., /var/cloud-integration/cloud-integration.json).
  • Adjust other values in tilt-values.yaml as needed during development.

Using Helm (Production)

# Add the OpenCost Helm repository
helm repo add opencost https://opencost.github.io/opencost-helm-chart
helm repo update

# Deploy OpenCost with MCP server (enabled by default)
helm install opencost opencost/opencost

# Access MCP server via port forwarding (example)
kubectl port-forward svc/opencost 8081:8081

The MCP server is enabled by default in the Helm chart. For custom configuration:

# Deploy with MCP server disabled
helm install opencost opencost/opencost \
  --set opencost.mcp.enabled=false

# Deploy with custom MCP port
helm install opencost opencost/opencost \
  --set opencost.mcp.port=9091

# Deploy with debug logging
helm install opencost opencost/opencost \
  --set opencost.mcp.extraEnv.MCP_LOG_LEVEL=debug

Configuration Summary

Configuration Command Description
Default helm install opencost opencost/opencost MCP enabled on port 8081
Disable --set opencost.mcp.enabled=false Completely disable MCP server
Custom Port --set opencost.mcp.port=9091 Use different port
Debug Mode --set opencost.mcp.extraEnv.MCP_LOG_LEVEL=debug Enable debug logging

MCP Client Configuration

Configure your MCP client (e.g., Cursor) to connect to the OpenCost MCP server:

Default configuration (port 8081):

{
  "mcpServers": {
    "opencost": {
      "type": "http",
      "url": "http://localhost:8081"
    }
  }
}

Custom port configuration:

{
  "mcpServers": {
    "opencost": {
      "type": "http",
      "url": "http://localhost:9091"
    }
  }
}

For Kubernetes deployments:

{
  "mcpServers": {
    "opencost": {
      "type": "http",
      "url": "http://opencost.opencost.svc.cluster.local:8081"
    }
  }
}

For external access (with LoadBalancer/Ingress):

{
  "mcpServers": {
    "opencost": {
      "type": "http",
      "url": "http://your-opencost-domain.com:8081"
    }
  }
}

Available MCP Tools

The MCP server provides these tools for AI agents:

get_allocation_costs

Retrieve cost allocation data with filtering and aggregation.

Parameters:

  • window (required): Time window (e.g., "7d", "1h", "30m")
  • aggregate (optional): Aggregation properties (e.g., "namespace", "pod", "node")
  • step (optional): Resolution step size
  • accumulate (optional): Whether to accumulate over time
  • share_idle (optional): Whether to share idle costs
  • include_idle (optional): Whether to include idle resources

get_asset_costs

Retrieve asset cost data including nodes, disks, load balancers, and more.

Parameters:

  • window (required): Time window (e.g., "7d", "1h", "30m")

get_cloud_costs

Retrieve cloud cost data with provider, service, and region filtering.

Parameters:

  • window (required): Time window (e.g., "7d", "1h", "30m")
  • aggregate (optional): Aggregation properties (e.g., "provider", "service", "region")
  • accumulate (optional): Time accumulation ("day", "week", "month")
  • provider (optional): Filter by cloud provider (e.g., "aws", "gcp", "azure")
  • service (optional): Filter by service (e.g., "ec2", "compute", "s3")
  • category (optional): Filter by category (e.g., "compute", "storage", "network")
  • region (optional): Filter by region (e.g., "us-west-1", "us-central1")
  • accountID (optional): Filter by account ID

Supported Asset Types

  • Node: Compute instances with CPU, RAM, GPU details
  • Disk: Storage volumes with usage and cost breakdown
  • LoadBalancer: Load balancer instances with IP and private status
  • Network: Network-related costs and usage
  • Cloud: Cloud service costs with credit information
  • ClusterManagement: Kubernetes cluster management costs

Example Usage

Once configured, AI agents can query cost data like:

// Get cost allocation for the last 7 days
const allocation = await mcpClient.callTool('get_allocation_costs', {
  window: '7d',
  aggregate: 'namespace,node'
});

// Get asset costs for the last 24 hours
const assets = await mcpClient.callTool('get_asset_costs', {
  window: '1d'
});

// Get cloud costs for AWS EC2 in us-west-1
const cloudCosts = await mcpClient.callTool('get_cloud_costs', {
  window: '7d',
  aggregate: 'service',
  provider: 'aws',
  service: 'ec2',
  accumulate: 'day',
  filter: 'regionID:"us-west-1"'
});

For detailed setup instructions and advanced configuration, see the Helm chart documentation.

Contributing

We :heart: pull requests! See CONTRIBUTING.md for information on building the project from source and contributing changes.

Community

If you need any support or have any questions on contributing to the project, you can reach us on CNCF Slack in the #opencost channel or attend the biweekly OpenCost Working Group community meeting from the Community Calendar to discuss OpenCost development.

FAQ

You can view OpenCost documentation for a list of commonly asked questions.