Amazon EKS — Kubecost & OpenCost

2 minute read

You can’t optimize what you can’t measure. Kubecost and OpenCost provide per-namespace, per-team, per-workload cost allocation — turning a single AWS bill into actionable cost breakdowns.


Kubecost on EKS

Install via Helm

helm repo add kubecost https://kubecost.github.io/cost-analyzer/

helm install kubecost kubecost/cost-analyzer \
  --namespace kubecost \
  --create-namespace \
  --set kubecostToken="YOUR_TOKEN" \
  --set prometheus.server.global.external_labels.cluster_id=my-cluster

Access Dashboard

kubectl port-forward svc/kubecost-cost-analyzer -n kubecost 9090:9090

Open http://localhost:9090 — shows:

  • Cost per namespace
  • Cost per deployment
  • Cost per label (team, environment)
  • Idle cost (wasted resources)
  • Right-sizing recommendations

Kubecost Cost Allocation

Kubecost allocates costs by:

Dimension Example How
Namespace production, staging Direct allocation
Label team=platform, team=backend Label-based allocation
Controller deployment/my-app Resource ownership
Pod Individual pod cost CPU + memory + storage + network

Cost Breakdown Example

Namespace: production
├── deployment/api-server:     $245/month (CPU: $120, Memory: $95, Storage: $30)
├── deployment/worker:         $180/month (CPU: $80, Memory: $70, Storage: $30)
├── deployment/redis:          $85/month  (CPU: $20, Memory: $50, Storage: $15)
└── Idle (requested but unused): $310/month  ← 38% waste

OpenCost (CNCF)

OpenCost is the open-source foundation that Kubecost is built on:

helm install opencost opencost/opencost \
  --namespace opencost \
  --create-namespace \
  --set opencost.exporter.defaultClusterId=my-cluster \
  --set opencost.ui.enabled=true
kubectl port-forward svc/opencost -n opencost 9003:9003
Feature Open Source (OpenCost) Kubecost Free Kubecost Business
Cost allocation ✅ ✅ ✅
Multi-cluster ❌ ❌ ✅
Savings recommendations ❌ ✅ ✅
Alerting ❌ ✅ ✅
SSO / RBAC ❌ ❌ ✅
Long-term storage ❌ 15 days Unlimited

AWS Cost Explorer for EKS

Use AWS cost allocation tags to break down EKS costs in Cost Explorer:

Tag Resources

# Tag node groups
aws eks tag-resource \
  --resource-arn arn:aws:eks:us-east-1:123456789012:nodegroup/my-cluster/production-nodes/abc123 \
  --tags team=platform,environment=production

# Tag EBS volumes (via StorageClass)

StorageClass with tags:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: gp3-tagged
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  tagSpecification_1: "team=backend"
  tagSpecification_2: "environment=production"

Enable Cost Allocation Tags

  1. Go to AWS Billing → Cost Allocation Tags
  2. Activate team, environment, kubernetes.io/cluster/my-cluster
  3. Wait 24 hours for tags to appear in Cost Explorer

Chargeback and Showback

Model Description Enforcement
Showback Show each team their costs Informational only
Chargeback Bill teams for actual usage Budget impact

Implementation with Kubecost

  1. Label all workloads with team label
  2. Configure Kubecost allocation:
    kubecostProductConfigs:
      labelMappingConfigs:
        enabled: true
        owner_label: "team"
        department_label: "department"
    
  3. Export reports via API:
    curl http://kubecost:9090/model/allocation?window=lastMonth&aggregate=label:team
    
  4. Send monthly reports to team leads

Cost Alerts

Kubecost Alerts

# values.yaml
alerts:
  - type: budget
    threshold: 1000
    window: monthly
    aggregation: namespace
    filter: production
    ownerContact:
      - owner: platform-team@company.com
        slack: "#cost-alerts"

AWS Budgets

aws budgets create-budget \
  --account-id 123456789012 \
  --budget '{
    "BudgetName": "EKS-Monthly",
    "BudgetType": "COST",
    "BudgetLimit": {"Amount": "3000", "Unit": "USD"},
    "TimeUnit": "MONTHLY",
    "CostFilters": {
      "Service": ["Amazon Elastic Kubernetes Service"]
    }
  }' \
  --notifications-with-subscribers '[{
    "Notification": {
      "NotificationType": "ACTUAL",
      "ComparisonOperator": "GREATER_THAN",
      "Threshold": 80,
      "ThresholdType": "PERCENTAGE"
    },
    "Subscribers": [{"SubscriptionType": "EMAIL", "Address": "team@company.com"}]
  }]'

Best Practices

  1. Install Kubecost day one — cost visibility from the start
  2. Label everything with team, environment, cost-center
  3. Use showback first — build awareness before enforcing chargeback
  4. Set AWS Budgets — catch unexpected cost spikes early
  5. Review monthly — costs shift as workloads change
  6. Activate cost allocation tags — enables AWS Cost Explorer breakdowns

Updated: