<p>I'm using kubernetes, and I want to create tool which have the ability to do <em>tcpdump</em> on some interfaces.</p>
<p>The problem is that this tool is controlled from container <em>container_A</em> in <em>POD_A</em> which doesn't have <em>tcpdump</em> installed in it (and I can't change it at this point), while <em>tcpdump</em> ability can be executed from <em>container_B</em> in <em>POD_B</em> (different from <em>POD_A</em>)</p>
<p>So the solution I choosed is to create <em>tcpdump</em> on different container (<em>container_B</em> in <em>POD_B</em>) and then move the dump file from <em>container_B</em> to <em>container_A</em>.
For this I used something close to solution which is provided here:<br />
<a href="https://stackoverflow.com/questions/59703610/copy-file-from-pod-to-host-by-using-kubernetes-python-client">Copy file from pod to host by using kubernetes python client</a></p>
<p>The problem now is that for using this solution I understand that the dump file should be closed on origin container before I copy it to the destination container. This can be causing a high disk usage on <em>container_A</em> which has a low disk space attached to it while <em>container_B</em> has a big disk space attached to it.</p>
<p><strong>I will paste the code from the link here for reference</strong></p>
<pre class="lang-py prettyprint-override"><code>def stream_copy_from_pod(self, pod_name, name_space, source_path, destination_path):
&quot;&quot;&quot;
Copy file from pod to the host.

:param pod_name: String. Pod name
:param name_space: String. Namespace
:param source_path: String. Pod destination file path
:param destination_path: Host destination file path
:return: bool
&quot;&quot;&quot;
command_copy = ['tar', 'cf', '-', source_path]
with TemporaryFile() as tar_buffer:
    exec_stream = stream(self.coreClient.connect_get_namespaced_pod_exec, pod_name, name_space,
                         command=command_copy, stderr=True, stdin=True, stdout=True, tty=False,
                         _preload_content=False)
    # Copy file to stream
    try:
        reader = WSFileManager(exec_stream)
        while True:
            out, err, closed = reader.read_bytes()
            if out:
                tar_buffer.write(out)
            elif err:
                logger.debug(&quot;Error copying file {0}&quot;.format(err.decode(&quot;utf-8&quot;, &quot;replace&quot;)))
            if closed:
                break
        exec_stream.close()
        tar_buffer.flush()
        tar_buffer.seek(0)
        with tarfile.open(fileobj=tar_buffer, mode='r:') as tar:
            member = tar.getmember(source_path)
            tar.makefile(member, destination_path)
            return True
    except Exception as e:
        raise manage_kubernetes_exception(e)
</code></pre>
<p>My question is can I use somehow the <code>exec_stream</code> with addaptaion provided in the example (or another <code>kubernetes-client</code> python api) and <code>tcpdump</code> command om <em>container_B</em> to stream the tcpdump straight to some tarball file (or another type of file) on <em>container_A</em>?</p>
<p>My assumption is that I just need to open stream <code>container_B</code> and send <code>command=&quot;tcpdump ...&quot;</code> in a way that it will be stream the tcpdump to stdout of this container and &quot;fetch&quot; + &quot;handle&quot; this stdout from the stream into file in <code>container_A</code>, but is there a better way to do it?</p>

ms_stud
<p>Eventually I've decided to use Async Thrift for &quot;management&quot; of this operation (created client-server) rather to use python kubernetes library.</p>
