Amazon EKS — Kubecost & OpenCost
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
- Go to AWS Billing → Cost Allocation Tags
- Activate
team,environment,kubernetes.io/cluster/my-cluster - 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
- Label all workloads with
teamlabel - Configure Kubecost allocation:
kubecostProductConfigs: labelMappingConfigs: enabled: true owner_label: "team" department_label: "department" - Export reports via API:
curl http://kubecost:9090/model/allocation?window=lastMonth&aggregate=label:team - 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
- Install Kubecost day one — cost visibility from the start
- Label everything with
team,environment,cost-center - Use showback first — build awareness before enforcing chargeback
- Set AWS Budgets — catch unexpected cost spikes early
- Review monthly — costs shift as workloads change
- Activate cost allocation tags — enables AWS Cost Explorer breakdowns