Skip to content

See Kubernetes costs by namespace

See what each namespace in an AKS, EKS or GKE cluster costs, without installing anything in the cluster. leancosts reads the allocation the cloud provider itself computes and serves it three ways: the Kubernetes tab on the Costs page, the get_kubernetes_costs tool on the leancosts MCP server, and GET /api/costs/kubernetes. leancosts is read-only here as everywhere: it never enables anything and never touches the cluster. For the full posture see Security and data handling.

  • The subscription / account / project that hosts the cluster is connected and has synced at least once.
  • For AWS, the connection reads a Cost and Usage Report. Cost Explorer does not carry namespace data, so a connection without a CUR cannot show it.
  • For Azure, the cluster is on the Standard or Premium tier. The add-on is not available on the Free tier.
  • Your agent is connected to leancosts (see Connect Claude to leancosts) if you want to ask rather than click.

1. Turn on cost allocation, once per cluster

Section titled “1. Turn on cost allocation, once per cluster”

This is the only step leancosts cannot do for you. Run the one for your cloud.

Azure (AKS), the cost analysis add-on, per cluster:

Terminal window
az aks update --ids "<cluster-resource-id>" \
--tier standard --enable-cost-analysis

Google Cloud (GKE): cost allocation, per cluster. Autopilot clusters already have it on:

Terminal window
gcloud container clusters update <name> \
--location <loc> --project <p> --enable-cost-allocation

AWS (EKS): an account-wide billing preference, not a CLI flag. In the AWS console, open Billing and Cost Management → Cost management preferences, enable Split cost allocation data, and then include it in the CUR export that the leancosts connection reads.

Each provider starts publishing within about a day (AWS prepares the current month, Google can take up to three days); nothing older is backfilled.

Every connector sync re-reads the recent window for the accounts it owns. You can trigger one from Connections or with the trigger_sync tool.

In the app: open the Costs page and pick the Kubernetes tab. One card per cluster with its provider, account and an allocation status chip; under it the namespaces ranked by cost with a share bar, and a 1 / 2-month toggle.

With an agent: some questions get_kubernetes_costs answers:

  • “Which namespaces cost the most in the payments cluster this month?”
  • “How much of that cluster is idle or unused?”
  • “Do all our clusters have cost allocation enabled?”

From a script: GET /api/costs/kubernetes?months=2 returns the same body.

Alongside the real namespaces, each provider emits its own buckets:

RowCloudMeaning
a namespaceallthe share of node, disk and load-balancer cost attributed to its pods
IdleAzurecapacity no namespace requested
SystemAzurekube-system and other platform namespaces
UnallocatedAzurecost the add-on could not attribute
ServiceAzurethe cluster’s uptime SLA fee
unusedAWSthe pods’ share of idle node capacity
goog-k8s-unsupported-skuGoogle CloudSKUs GKE cost allocation does not split
goog-k8s-unknownGoogle Cloudusage GKE could not attribute to a namespace

Open the Costs page’s Kubernetes tab, or call the tool. You should see every cluster leancosts knows, per cloud, with its status chip, and namespace rows under the clusters where allocation is on. If a cluster shows rows, it worked.

The response lists every cluster with its allocation flag, so the two failure modes are distinguishable:

  • Allocation off on every cluster: step 1 has not happened. The empty state shows the exact command to run.
  • Allocation on but no rows: the provider has not published the first day yet, or the connector has not synced since. Try again after the next sync.
  • An EKS cluster with no rows: leancosts cannot read the AWS preference, so check that Split cost allocation data is both enabled and included in the CUR export the connection reads.