github.com/inspektor-gadget/inspektor-gadget@v0.28.1/docs/builtin-gadgets/top/tcp.md (about)

     1  ---
     2  title: 'Using top tcp'
     3  weight: 20
     4  description: >
     5    Periodically report TCP activity.
     6  ---
     7  
     8  The top tcp gadget is used to visualize active TCP connections.
     9  
    10  ### On Kubernetes
    11  
    12  First, we need to create one pod for us to play with:
    13  
    14  ```bash
    15  $ kubectl run test-pod --image busybox:latest sleep inf
    16  ```
    17  
    18  You can now use the gadget, but output will be empty:
    19  
    20  ```bash
    21  $ kubectl gadget top tcp
    22  K8S.NODE         K8S.NAMESPACE    K8S.POD          K8S.CONTAINER    PID       COMM      IP SRC                   DST                   SENT     RECV
    23  ```
    24  
    25  Indeed, it is waiting for TCP connection to occur.
    26  So, open *another terminal* and keep and eye on the first one, `exec` the container and use `wget`:
    27  
    28  ```bash
    29  $ kubectl exec -ti test-pod -- wget 1.1.1.1
    30  ```
    31  
    32  On *the first terminal*, you should see:
    33  
    34  ```
    35  K8S.NODE           K8S.NAMESPACE K8S.POD    CONTAINER   PID         COMM       IP SRC                        DST                  SENT       RECV      
    36  minikube-docker    default       test-pod   test-pod    289548      wget       4  p/default/test-pod:47228   r/1.1.1.1:443        296B       15.49KiB  
    37  minikube-docker    default       test-pod   test-pod    289540      wget       4  p/default/test-pod:42604   r/1.1.1.1:80         70B        381B      
    38  ```
    39  
    40  This line corresponds to the TCP connection initiated by `wget`.
    41  
    42  #### Clean everything
    43  
    44  Congratulations! You reached the end of this guide!
    45  You can now delete the pod you created:
    46  
    47  ```bash
    48  $ kubectl delete pod test-pod
    49  pod "test-pod" deleted
    50  ```
    51  
    52  ### With `ig`
    53  
    54  Start a container that runs `nginx` and access it locally:
    55  
    56  ```bash
    57  $ docker run --rm --name test-top-tcp nginx /bin/sh -c 'nginx; while true; do curl localhost; sleep 1; done'
    58  ```
    59  
    60  Start the gadget, it'll show the different connections created the localhost:
    61  
    62  ```bash
    63  $ sudo ig top tcp -c test-top-tcp
    64  RUNTIME.CONTAINERNAME      PID         COMM           IP SRC                               DST                               SENT          RECV
    65  test-top-tcp               2177846     nginx          4  127.0.0.1:80                      127.0.0.1:53130                   238B          73B
    66  test-top-tcp               2178303     curl           4  127.0.0.1:53130                   127.0.0.1:80                      73B           853B
    67  ```