top_tcp
The top_tcp gadget reports tcp send receive activity by connection.
Getting started
Running the gadget:
- kubectl gadget
- ig
$ kubectl gadget run ghcr.io/inspektor-gadget/gadget/top_tcp:latest [flags]
$ sudo ig 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
- kubectl gadget
- ig
First, we need to create one pod for us to play with:
kubectl run mypod --image busybox:latest sleep inf
First, we need to create a container for us to play with:
docker run -d --name mycontainer busybox:latest sleep inf
You can now use the gadget, but output will be empty:
- kubectl gadget
- ig
$ kubectl gadget run top_tcp:latest --podname mypod
K8S.NODE K8S.NAMESPACE K8S.PODNAME K8S.CONTAINERNAME PID SRC DST COMM SENT RECEIVED
$ sudo ig run top_tcp:latest --containername mycontainer
RUNTIME.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 gadget
- ig
$ 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
$ docker exec mycontainer wget inspektor-gadget.io
Connecting to inspektor-gadget.io (188.114.97.7:80)
Connecting to inspektor-gadget.io (188.114.96.7: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:
- kubectl gadget
- ig
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
RUNTIME.CONTAINERNAME PID SRC DST COMM SENT RECEIVED
mycontainer 79480 172.17.0.4:42522 188.114.97.7:80 wget 82 588
mycontainer 79499 172.17.0.4:54254 188.114.96.7:443 wget 320 42655
These lines correspond to the TCP connection initiated by wget
.
Finally, clean the system:
- kubectl gadget
- ig
kubectl delete pod mypod
docker rm -f mycontainer