容器内抓包定位网络问题
使用脚本一键进入 pod netns 抓包
kubectl get pod -o widefunction e() { set -eu ns=${2-"default"} pod=`kubectl -n $ns describe pod $1 | grep -A10 "^Containers:" | grep -Eo 'docker://.*$' | head -n 1 | sed 's/docker:\/\/\(.*\)$/\1/'` pid=`docker inspect -f {{.State.Pid}} $pod` echo "entering pod netns for $ns/$1" cmd="nsenter -n --target $pid" echo $cmd $cmd}e istio-galley-58c7c7c646-m6568 istio-systeme proxy-5546768954-9rxg6 # 省略 NAMESPACE 默认为 defaulttcpdump -i eth0 -w test.pcap port 80# 使用 telnet 连上并发送一些测试文本,比如 "lbtest",# 用下面语句可以看发送的测试报文有没有到容器tcp contains "lbtest"# 如果容器提供的是http服务,可以使用 curl 发送一些测试路径的请求,# 通过下面语句过滤 uri 看报文有没有都容器http.request.uri=="/mytest"脚本原理
kubectl describe pod <pod> -n mserviceLast updated