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

     1  ---
     2  title: 'Using trace tcpretrans'
     3  weight: 20
     4  description: >
     5      Trace TCP retransmissions.
     6  ---
     7  
     8  The trace tcpretrans gadget traces TCP retransmissions by the kernel.
     9  
    10  ### On Kubernetes
    11  
    12  In terminal 1, start the trace tcpretrans gadget:
    13  
    14  ```bash
    15  $ kubectl gadget trace tcpretrans
    16  K8S.NODE     K8S.NAMESP… K8S.POD     K8S.CONTAI… PID     COMM  IP SRC                    DST                    STATE     TCPFLA… TYPE
    17  ```
    18  
    19  In terminal 2, start a pod and configure the network emulator to drop 25% of the packets. This will cause TCP retransmissions:
    20  
    21  ```bash
    22  $ kubectl create service nodeport nginx --tcp=80:80
    23  $ kubectl create deployment nginx --image=nginx
    24  $ kubectl run --rm -ti --privileged --image ubuntu shell -- bash
    25  root@shell:/# apt-get update
    26  root@shell:/# apt install -y iproute2 curl
    27  root@shell:/# tc qdisc add dev eth0 root netem drop 25%
    28  root@shell:/# curl nginx
    29  ```
    30  
    31  The results in terminal 1 will show that some TCP transmissions cause by the dropped packets:
    32  
    33  ```
    34  K8S.NODE     K8S.NAMESP… K8S.POD     K8S.CONTAI… PID     COMM  IP SRC                    DST                    STATE     TCPFLA… TYPE
    35  miniku…ocker default     shell       shell       60274   curl  4  p/default/shell:46022  s/default/nginx:80     ESTABLIS…         LOSS
    36  miniku…ocker default     shell       shell       60274   curl  4  p/default/shell:46022  s/default/nginx:80     ESTABLIS… PSH|ACK RETRANS
    37  ```
    38  
    39  ### With `ig`
    40  
    41  In terminal 1, start the trace tcpretrans gadget:
    42  
    43  ```bash
    44  $ sudo ig trace tcpretrans -r docker -c netem
    45  CONTAINER  PID   COMM  IP SRC               DST          STATE        TCPFLAGS
    46  ```
    47  
    48  In terminal 2, start a container, configure the network emulator to drop 25% of the packets, and download a web page:
    49  
    50  ```bash
    51  $ docker run -ti --rm --cap-add NET_ADMIN --name=netem wbitt/network-multitool -- /bin/bash
    52  # tc qdisc add dev eth0 root netem drop 25%
    53  # wget 1.1.1.1
    54  ```
    55  
    56  The container needs NET_ADMIN capability to manage network interfaces
    57  
    58  The results in terminal 1 will show some TCP transmissions caused by the dropped packets:
    59  
    60  ```
    61  RUNTIME.CONTAINERNAME PID        COMM         IP SRC                          DST                         STATE       TCPFLAGS    TYPE
    62  netem                 21686      wget         4  10.10.0.3:46326              1.1.1.1:80                  SYN_SENT    SYN         RETRANS
    63  netem                 21686      wget         4  10.10.0.3:46326              1.1.1.1:80                  ESTABLISHED             LOSS
    64  ```