 In this video series, we are using Pixie to estimate the cost of our Kubernetes services. In the previous two videos, we estimated CPU and memory costs per service. In this video, we'll estimate network egress costs for our services. And in the next video, we'll compute the amortized costs per request for each service. Okay, so what is Pixie? Pixie is an open-source observability tool for Kubernetes applications. Pixie uses EBPF to automatically collect a lot of data out of the box, such as infrastructure and network metrics, application profiles, and full-body requests. Pixie is a scriptable interface, so you can modify existing scripts or write custom scripts to do the analysis that you're interested in. In this video, we will be writing a custom script to get visibility into the cost of our services. In this video, we are going to estimate network egress costs. Now, most cloud providers don't charge for traffic coming into the cluster, so we only need to calculate egress traffic. Network egress costs can be calculated by multiplying the number of gigabytes of traffic leaving our cluster times the price per gigabyte. So here is Pixie's live UI, and from this HTTP service map, you can see all the microservices that are talking to each other in my cluster. I'm going to open the ScratchPred script. And if I open the editor, you can see the custom network egress cost script I've pasted in here. So let's run the script. This script outputs two tables. The first table shows the estimated network cost by service, and you can sort this cost. And then the bottom one just sums the individual services network's cost into a total cost. Let's take a closer look at the script. So this script loads the last one hour of Pixie's constats table into a data frame. The connection stats table traces all traffic in your Kubernetes cluster at the connection level. Now, we are only charged for outbound traffic from the cluster, so we need to filter for that. To do that, basically, we are checking to see if the remote address resolves to a pod name. If it does, then it's not outbound traffic. So we filter that out. The other thing we are also doing is filtering out the local host. So we group the outbound traffic per service here. And these fields are counters per UPID, so we're basically taking the min and max, so the starting and ending value over the time window we're interested in. And then we do the delta of that to get the total bytes transferred. Finally, we're summing by service, and then we convert bytes to gigabytes. And then we multiply by the egress cost per gigabyte, and then the number of hours in a year to get the yearly cost. Now, these scripts are all public, so you can try them out by following the link in the video description. If you want to play around with a script, it should be easy to modify it to slice costs by pod or namespace. In the next video, we'll sum the CPU memory and network costs and compute the amortized costs per request for each service. So be sure to check that out.