$ ./get_pod_interface.sh my-pod
Internal interface index: 281. Searching for it on host...
Host interface: veth0f6a8d6
$ sudo tcpdump -i veth0f6a8d6 port 80
Created
July 29, 2019 07:47
-
-
Save lavie/80f53eeb09bac9fc1223a850f6977046 to your computer and use it in GitHub Desktop.
how to tcpdump traffic from a specific kubernetes pod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
POD_NAME="$1" | |
IFACE="$(kubectl exec -t "$POD_NAME" -- bash -c "cat /sys/class/net/eth0/iflink")" | |
echo "Internal interface index: $IFACE. Searching for it on host..." | |
for i in /sys/class/net/veth*/ifindex; do | |
if grep "$IFACE" <$i >/dev/null; then | |
echo -n "Host interface: " | |
echo "$i" | grep -o -E "veth[^/]*" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment