Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes - how to download a PersistentVolume's content

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

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

How can I get the contents of a PersistentVolume?

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?

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

like image 435
Ondra Žižka Avatar asked May 16 '18 16:05

Ondra Žižka


People also ask

How do you view the contents of PVC pipe?

First, find out your pvc's mountPath. Your data sits there. Second, you can access it from the pod that uses the PersistentVolumeClaim. Fire up a terminal on the pod and use your favourite tools like ls and df to list files or see stats of the volume usage.


Video Answer


1 Answers

I can think about two options to fulfill your needs:

  1. Create a pod with the PV attached to it and use kubectl cp to copy the contents wherever you need. You could for example use a PodSpec similar to the following:
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

Please note that mypvc should be the name of the PersistentVolumeClaim that is bound to the PV you want to copy data from.

Once the pod is running, you can run something like below to copy the data from any machine that has kubectl configured to connect to your cluster:

kubectl cp dataaccess:/data data/
  1. 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.
like image 172
whites11 Avatar answered Oct 19 '22 02:10

whites11