Back to Blog

See Your Kubernetes Cost Per Pod with eBPF

You already have CPU and memory per pod. The part of the bill nobody can explain is network — and that’s the specific problem eBPF is good at. With the honest caveats.

The cloud invoice stops at the node. It tells you a node cost some amount this month; it has nothing to say about which of the forty pods on it, from six teams, actually spent the money. Closing that gap is what “per-pod cost” is about — and there’s a lot of hand-waving around it, so it’s worth being precise about what’s actually hard and where eBPF earns its place.

Most of this you already have

CPU and memory per pod are not the hard part. cAdvisor exposes per-container usage, kube-state-metrics gives you the requests, and a tool like OpenCost already turns “node price × usage share” into per-namespace dollars. If you only need compute attribution, you probably don’t need eBPF at all — wire up what you’ve got and move on.

The genuinely hard parts are two: the shared and idle cost (the half-empty node, the system DaemonSets, the control plane — somebody has to be charged for it, and the rule you choose changes everyone’s number), and network. Network is the one that’s both expensive and invisible.

Why network is the mystery

Cross-AZ traffic and egress out of the VPC are a real line on the bill, and standard tooling can’t tell you which pod caused them. By the time a packet reaches the cloud’s billing meter, the pod identity is gone — it’s just an IP, and IPs churn as pods reschedule. VPC flow logs see the bytes but not the workload, and they’re coarse and not cheap to store at volume. So “why is egress $X this month” usually ends in a shrug.

This is the gap eBPF is actually good at.

What eBPF buys you here

eBPF runs small sandboxed programs in the kernel, attached to events — including the network path — so you can label flows with workload identity at the source, before the IP loses its meaning. Concretely, for cost that’s:

  • bytes per source/destination workload, so cross-AZ and egress traffic gets attributed to the pod and team that generated it;
  • continuous measurement at low overhead, because there’s no userspace round trip per packet.

CPU and memory it can also read per cgroup, but as above, that’s not where it’s saving you — the network identity is.

The honest cost of getting it

The clean path is Cilium with Hubble: if Cilium is already your CNI, Hubble gives you eBPF flow visibility and you’re most of the way there. If it isn’t your CNI, be clear-eyed — swapping the CNI on a running cluster to get cost dashboards is a real migration with real risk, and rarely worth it on the cost argument alone. In that case a standalone eBPF agent (OpenCost’s, or a lightweight DaemonSet feeding Prometheus) gets you the network attribution without re-plumbing the cluster.

Either way, two caveats that decide whether the numbers are trustworthy:

  • Attribution is a model, not a meter. Idle and shared cost has to be assigned by some rule. Make the rule explicit and visible, or the first time a team disputes their number you’ll have no answer.
  • Pricing has to be real. An eBPF agent counts bytes; it doesn’t know your cross-AZ rate or your committed-use discounts. Feed it real cloud pricing or the dollar figures are decoration.

And the usual: recent-enough kernels for the modern features, and verify the overhead on a canary pool under real load rather than trusting the brochure’s “negligible.”

When to actually reach for it

If your bill is mostly compute, skip all of this and go rightsize — that’s the bigger lever and you already have the data. Pull eBPF in when egress is the unexplained part of the invoice and “who owns this traffic” keeps coming up without an answer. That’s a narrow, real problem, and it’s the one eBPF solves better than anything else. Used for that, it stops being a buzzword and starts paying for the agent.

Continue reading