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

<p>I've tried this:</p>

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

<p>(<code>tcpdumper</code> is just a thin wrapper around <code>tcpdump</code> which runs as a helper container in the pod).</p>

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

<p>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.</p>

<p>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 <code>tail</code>; when I do this in this fashion, <code>tail</code> appears to add newline characters.  I presume this is because <code>tail</code> is not intended to handle binary data.</p>

<p>If I run <code>tcpdump</code> directly on the pod, write it to a .pcap file there, and then transfer that file using <code>kubectl cp</code>, 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 <code>tail</code> method above is that there are extraneous characters ("0xD", which is the newline character) every so often.</p>

<p>Any ideas?</p>

Mark
<p>I'm not sure what's causing tail to randomly insert newline chars, and I'm not in a position to reproduce your issue but I do have a couple of ideas:</p>
<p>1: base64 encode the file on the server as it's being written to, and base64 decode it as you read it on your local machine.</p>
<p>2: Instead of writing to a file, try writing to a fifo (mkfifo), which you can simply cat, rather than tailing.</p>
<p>Without knowing your situation better I can't really talk intelligently on whether or not these are applicable to your situation or not, but thought they'd be worth mentioning.</p>
