Skip to main content
Version: latest

top_tcp

The top_tcp gadget reports tcp send receive activity by connection.

Getting started

Running the gadget:

$ kubectl gadget run ghcr.io/inspektor-gadget/gadget/top_tcp:latest [flags]

Flags

--family

Trace traffic from the specified IPv family. Can be either 4 or 6. Specifying -1 equals to no filtering

Default value: "-1"

--pid

Show only events generated by process with this PID

Default value: "0"

Guide

First, we need to create one pod for us to play with:

kubectl run mypod --image busybox:latest sleep inf

You can now use the gadget, but output will be empty:

$ kubectl gadget run top_tcp:latest --podname mypod
K8S.NODE K8S.NAMESPACE K8S.PODNAME K8S.CONTAINERNAME PID SRC DST COMM SENT RECEIVED

Indeed, it is waiting for TCP connection to occur. So, open another terminal and keep and eye on the first one, exec the container and use wget:

$ kubectl exec -ti mypod -- wget inspektor-gadget.io
Connecting to inspektor-gadget.io (188.114.96.0:80)
Connecting to inspektor-gadget.io (188.114.96.0:443)
wget: note: TLS certificate validation not implemented
saving to 'index.html'
index.html 100% |**********************************************************************************************************| 37851 0:00:00 ETA
'index.html' saved

On the first terminal, you should see:

K8S.NODE     K8S.NAMESPACE          K8S.PODNAME            K8S.CONTAINERNAME               PID SRC                                 DST                                COMM          SENT          RECEIVED
aks-agentpo… default mypod mypod 3602459 p/default/mypod:57076 188.114.97.7:443 wget 320 42652
aks-agentpo… default mypod mypod 3602452 p/default/mypod:49538 188.114.96.7:80 wget 0 582

These lines correspond to the TCP connection initiated by wget.

Finally, clean the system:

kubectl delete pod mypod