How can I tail a remote binary file?

我只是一个虾纸丫 提交于 2020-06-17 15:57:05

问题


I'm looking for a way to stream ("tail") a binary file on a Kubernetes pod to my local machine.

I've tried this:

kubectl exec -it app-service-58697cf7c9-nnzgh -c tcpdumper -- tail -f -c +0 /output.pcap

(tcpdumper is just a thin wrapper around tcpdump which runs as a helper container in the pod).

This almost works. I'm able to view a stream of binary data on my local machine when I run this command.

The end goal of what I'm trying to do here is that I'd like to take this binary stream of pcap data and pipe it to Wireshark running on my machine. That's what doesn't work, and it's because the data isn't exactly what's being written on the pod.

What's relevant though isn't that this is Kubernetes, or that it's packet capture. The issue appears to be with how I'm streaming this data using tail; when I do this in this fashion, tail appears to add newline characters. I presume this is because tail is not intended to handle binary data.

If I run tcpdump directly on the pod, write it to a .pcap file there, and then transfer that file using kubectl cp, and then load that file into Wireshark, it works and I can view the network traffic. I can see using a hex editor that the difference between this method and the tail method above is that there are extraneous characters ("0xD", which is the newline character) every so often.

Any ideas?

来源:https://stackoverflow.com/questions/62337901/how-can-i-tail-a-remote-binary-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!