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
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?
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.
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.
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With