7

I have a k8s cluster which uses rancher.io/local-path. There is a PV there


    $ kubectl describe pv pvc-979af6ff-3617-4707-8a2c-b6c4ac00043f
    Name:              pvc-979af6ff-3617-4707-8a2c-b6c4ac00043f
    Labels:            <none>
    Annotations:       pv.kubernetes.io/provisioned-by: rancher.io/local-path
    Finalizers:        [kubernetes.io/pv-protection]
    StorageClass:      local-path
    Status:            Bound
    Claim:             gitlab/gitlab-prometheus-server
    Reclaim Policy:    Delete
    Access Modes:      RWO
    VolumeMode:        Filesystem
    Capacity:          8Gi
    Node Affinity:     
      Required Terms:  
        Term 0:        kubernetes.io/hostname in [agent-1]
    Message:           
    Source:
        Type:          HostPath (bare host directory volume)
        Path:          /var/lib/rancher/k3s/storage/pvc-979af6ff-3617-4707-8a2c-b6c4ac00043f_gitlab_gitlab-prometheus-server
        HostPathType:  DirectoryOrCreate
    Events:            <none>

I would like to move that PV to another node, agetn-5. How can I achieve that? Important point that PV in question is rancher.io/local-path provisioned.

Alex_www
  • 71
  • 3
  • 2
    I don't believe this is possible. You will mostly likely need to manually copy the data to the new volume. This is one of many reasons why network disks like block storage are typical for k8s. – D-S Apr 01 '22 at 17:29

1 Answers1

1

It isn't possible to do this in a single step.

But you can:

  1. Access the K8s cluster where PVC exists
  2. Create a Deployment (or single Pod) that mounts PVC on the path you prefer (Example /xyz)
  3. Run
   kubectl -n NAMESPACE cp POD_NAME:/xyz /tmp/

to locally copy the contents of the /xyz folder to the /tmp path

  1. Logout from K8s cluster

  2. Login to the K8s cluster where data will be migrated

  3. Create new PVC

  4. Create a Deployment (or Single Pod) that mounts the PVC on the path you prefer (Example /new-xyz)

  5. Run

   kubectl -n NAMESPACE cp /tmp/xyz/ POD_NAME:/new-xyz/

to copy the local content to the path /new-xyz

glv
  • 994
  • 1
  • 1
  • 15