使用ksniff分析k8s pod的抓包分析

使用ksniff分析k8s pod的抓包分析

ksniff是一个kubectl插件,利用tcpdumpWiresharkKubernetes集群中的任何pod进行远程捕获。

可以得到Wireshark的全部功能,而对你正在运行的pods影响最小。

介绍
当使用微服务时,很多时候获取微服务和它的依赖之间的网络活动的捕获是非常有用的。

ksniff使用kubectl上传静态编译的tcpdump二进制文件到你的pod,并将它的输出重定向到你的本地Wireshark,以获得流畅的网络调试体验。

github上下载ksniff的发布包,执行以下命令安装

unzip ksniff.zip
make install

ksniff使用

kubectl < 1.12:
kubectl plugin sniff <POD_NAME> [-n <NAMESPACE_NAME>] [-c <CONTAINER_NAME>] [-i <INTERFACE_NAME>] [-f <CAPTURE_FILTER>] [-o OUTPUT_FILE] [-l LOCAL_TCPDUMP_FILE] [-r REMOTE_TCPDUMP_FILE]

kubectl >= 1.12:
kubectl sniff <POD_NAME> [-n <NAMESPACE_NAME>] [-c <CONTAINER_NAME>] [-i <INTERFACE_NAME>] [-f <CAPTURE_FILTER>] [-o OUTPUT_FILE] [-l LOCAL_TCPDUMP_FILE] [-r REMOTE_TCPDUMP_FILE]

POD_NAME: Required. the name of the kubernetes pod to start capture it's traffic.
NAMESPACE_NAME: Optional. Namespace name. used to specify the target namespace to operate on.
CONTAINER_NAME: Optional. If omitted, the first container in the pod will be chosen.
INTERFACE_NAME: Optional. Pod Interface to capture from. If omitted, all Pod interfaces will be captured.
CAPTURE_FILTER: Optional. specify a specific tcpdump capture filter. If omitted no filter will be used.
OUTPUT_FILE: Optional. if specified, ksniff will redirect tcpdump output to local file instead of wireshark. Use '-' for stdout.
LOCAL_TCPDUMP_FILE: Optional. if specified, ksniff will use this path as the local path of the static tcpdump binary.
REMOTE_TCPDUMP_FILE: Optional. if specified, ksniff will use the specified path as the remote path to upload static tcpdump to.

ksniff具有两种方式,第一种static-tcpdump,直接上传static-tcpdump到目标pod的容器中,然后启动本地的Wireshark对目标容器进行抓包分析。该方法要求目标容器具有sh命令执行工具。

第二种特权模式privileged,使用-p参数指定,该方式会在目标集群中创建dindpod容器,并且该pod将可以访问节点docker守护进程。ksniff将使用该pod执行一个连接到目标容器网络命名空间的容器,并执行实际的网络捕获。该方法需要maintained/tcpdump:latestdocker:latest两个镜像。

注:大前提是运行ksniff上面安装Wireshark包,ubuntu下使用apt-get install Wireshark进行安装。也可以集成其他工具,例如tshark ,运行命令kubectl sniff pod-name -f "port 80" -o - | tshark -r -

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值