In this tutorial, we are going to see how to share a non-bootable persistent storage disk between two VM instances. Keep in mind that, the instance which is going to get accessed remains in read-only permission.
Benefits of sharing disks
- Less storage consumption between multi-instance application
- Save replication practice
- Reduce the billing
- Read operations can be distributed
- Ease of access
Steps to share the disk
In this example, let us consider that we have an instance called datacloudies-template-1 which holds two standard persistent disks.
Disk-1 is the non-bootable instance that is going to be shared with another instance called datacloudies-2.
Let us connect to the gcloud and attach the disk-1 to datacloudies-2 instance.
gcloud compute instances attach-disk datacloudies-2 --zone us-central1-a --disk disk-1 --mode ro
Make sure to provide the mode as read-only. Otherwise this will not allow you to attach as RW.
Verify the disk-1 attached to both the instances,
Go to disk and check the status,
Now, disk-1 is attached to both datacloudies-2 and datacloudies-template-1 instances. If you want to format and mount the filesystem, then follow this tutorial.