<p>I have a test executor <code>Pod</code> in K8s cluster created through helm, which asks for a dynamically created <code>PersistentVolume</code> where it stores the test results.</p>

<p>Now I would like to get the contents of this volume. It seems quite natural thing to do.
I would expect some <code>kubectl download pv &lt;id&gt;</code>. But I can't google up anything.</p>

<p><strong>How can I get the contents of a <code>PersistentVolume</code>?</strong></p>

<p>I am in AWS EKS; so AWS API is also an option. Also I can access ECR so perhaps I could somehow store it as an image and download?</p>

<p>Or, in general, I am looking for a way to transfer a directory, can be even in an archive. But It should be <em>after</em> the container finished and doesn't run anymore.</p>

<p>I can think about two options to fulfill your needs:</p>
<ol>
<li>Create a pod with the PV attached to it and use <code>kubectl cp</code> to copy the contents wherever you need. You could for example use a <code>PodSpec</code> similar to the following:</li>
</ol>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: dataaccess
spec:
  containers:
  - name: alpine
    image: alpine:latest
    command: ['sleep', 'infinity']
    volumeMounts:
    - name: mypvc
      mountPath: /data
  volumes:
  - name: mypvc
    persistentVolumeClaim:
      claimName: mypvc
</code></pre>
<p>Please note that <code>mypvc</code> should be the name of the <code>PersistentVolumeClaim</code> that is bound to the PV you want to copy data from.</p>
<p>Once the pod is running, you can run something like below to copy the data from any machine that has <code>kubectl</code> configured to connect to your cluster:</p>
<pre><code>kubectl cp dataaccess:/data data/
</code></pre>
<ol start="2">
<li>Mount the PV's EBS volume in an EC2 instance and copy the data from there. This case is less simple to explain in detail because it needs a little more context about what you're trying to achieve.</li>
</ol>
