Kubernetes - how to download a PersistentVolume's content Kubernetes - how to download a PersistentVolume's content kubernetes kubernetes

Kubernetes - how to download a PersistentVolume's content


I can think about two options to fulfil 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: v1kind: Podmetadata:  name: dataaccessspec:  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.


Here is a properly formatted example from @whites11

apiVersion: v1kind: Podmetadata:  name: dataaccessspec:  containers:    - name: alpine      image: alpine:latest      command: ["sleep", "infinity"]      volumeMounts:        - name: mypvc          mountPath: /inbound  volumes:    - name: mypvc      persistentVolumeClaim:        claimName: mypvc