github.com/inspektor-gadget/inspektor-gadget@v0.28.1/docs/builtin-gadgets/snapshot/socket.md (about) 1 --- 2 title: 'Using snapshot socket' 3 weight: 20 4 description: > 5 Gather information about TCP and UDP sockets. 6 --- 7 8 The snapshot socket gadget gathers information about TCP and UDP sockets. 9 10 ### On Kubernetes 11 12 We will start this demo by using nginx to create a web server on port 80: 13 14 ```bash 15 $ kubectl create ns test-socketcollector 16 namespace/test-socketcollector created 17 $ kubectl run --restart=Never -n test-socketcollector --image=nginx nginx-app --port=80 18 pod/nginx-app created 19 ``` 20 21 Wait for the pod to get ready: 22 23 ```bash 24 $ kubectl wait --timeout=-1s -n test-socketcollector --for=condition=ready pod/nginx-app ; kubectl get pod -n test-socketcollector 25 pod/nginx-app condition met 26 NAME READY STATUS RESTARTS AGE 27 nginx-app 1/1 Running 0 46s 28 ``` 29 30 We will now use the snapshot socket gadget to retrieve the TCP/UDP sockets information 31 of the nginx-app pod. Notice we are filtering by namespace but we could have 32 done it also using the podname or labels: 33 34 ```bash 35 $ kubectl gadget snapshot socket -n test-socketcollector 36 K8S.NODE K8S.NAMESPACE K8S.POD PROTOCOL SRC DST STATUS 37 minikube-docker test-socketcollect… nginx-app TCP r/0.0.0.0:80 r/0.0.0.0:0 LISTEN 38 ``` 39 40 In the output, "SRC" is the local IP address and port number pair. 41 If connected, "DST" is the remote IP address and port number pair, 42 otherwise, it will be "0.0.0.0:0". While "STATUS" is the internal 43 status of the socket. 44 45 Now, modify the nginx configuration to listen on port 8080 instead of 80 and reload the daemon: 46 47 ```bash 48 $ kubectl exec -n test-socketcollector nginx-app -- /bin/bash -c "sed -i 's/listen \+80;/listen\t8080;/g' /etc/nginx/conf.d/default.conf && exec nginx -s reload" 49 [...] signal process started 50 ``` 51 52 Now, we can check again with the snapshot socket gadget what the active socket is: 53 54 ```bash 55 K8S.NODE K8S.NAMESPACE K8S.POD PROTOCOL SRC DST STATUS 56 minikube-docker test-socketcollect… nginx-app TCP r/0.0.0.0:8080 r/0.0.0.0:0 LISTEN 57 ``` 58 59 Delete test namespace: 60 61 ```bash 62 $ kubectl delete ns test-socketcollector 63 namespace "test-socketcollector" deleted 64 ``` 65 66 ### With `ig` 67 68 The `snapshot socket` is not available on `ig` yet. Please check https://github.com/inspektor-gadget/inspektor-gadget/issues/744.