Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pre-populate a ReadOnlyMany Persistent Volume

I am trying to create a deployment in GKE that uses multiple replicas. I have some static data which I want to have available in every pod. This data will not be updated, no write is required.

I decided to use a PV with a corresponding PVC with the ReadOnlyMany storage class. The thing is, I do not know how to actually transfer my data to the volume - since it is read-only. I tried using

gcloud compute scp /local/path instance:/remote/path

but of course, I get a permission error. I then tried creating a new PV via the console. I attached it to a VM with

gcloud compute instances attach disk

mounted and formatted the disk, transfered my data, unmounted the disk, detached it from the VM and finally created a PVC following the documentation. I changed the storage class to ReadOnlyMany, the only difference.

But still, when I'm trying to scale my deployment to more than one replicas I get an error saying the disk is already attached to another node.

So, how can I create a volume that is to be used in ReadOnlyMany and populate the disk with data? Or is there a better approach since no write is required?

Thanks in advance

like image 280
Nikolaos Paschos Avatar asked Sep 02 '19 08:09

Nikolaos Paschos


People also ask

What are persistent volumes?

Persistent volumes are cluster resources that are also volume plug-ins with a life cycle independent of other pods. This tutorial introduces persistent volumes, including some use cases, and helps the reader gain a complete understanding of how they can be effectively set up and used. What are Persistent Volumes? What are StorageClasses?

What is persistent volume in Kubernetes?

Persistent volume (PV) is a piece of storage provided by an administrator in a Kubernetes cluster. When a developer needs persistent storage for an application in the cluster, they request that storage by creating a persistent volume claim (PVC) and then mounting the volume to a path in the pod.

How do I manually create a persistentvolumeclaim?

Manually creating a PersistentVolumeClaim and a PersistentVolume, binding them together, and referring to the PersistentVolumeClaim in a Pod specification. Use a StatefulSet to automatically generate PersistentVolumeClaims which are bound to manually generated PersistentVolumes corresponding to a series of preexisting persistent disks.

How do I create a read-only volume in Kubernetes?

To create the PersistentVolume and PersistentVolumeClaim use kubectl apply -f read-only-pd.yaml. When using this PersistentVolumeClaim in your workloads, you need to specify readOnly: true in the volumeMounts and volumes sections of your Pod specification, as shown in the following example:


1 Answers

Worked for me. Have you specified readOnly: true when using persistent volume claim in the Pod template?

volumes:
- name: my-volume
  persistentVolumeClaim:
    claimName: my-readonly-pvc
    readOnly: true

See details here https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/readonlymany-disks

like image 114
Ievgen Goichuk Avatar answered Nov 15 '22 09:11

Ievgen Goichuk