GCP Create Disk from Snapshot

Here’s how to create a disk from a snapshot via Google SDK.

gcloud compute disks create new-server-disk-2 \
--project=project-name \
--source-snapshot=server-disk-2 \
--zone=us-central1-b

GCP CLI Create Firewall

Here’s how to add a firewall rule in Google Cloud Platform CLI

gcloud compute firewall-rules create "firewall-name" \
--description="firewall-description" \
--priority "1000" \
--direction INGRESS \
--action allow \
--network "network-name" \
--target-service-accounts="service@account.net" \
--source-ranges="10.0.0.0/8" \
--rules tcp:9001

Describe firewall rule.

gcloud compute firewall-rules describe firewall-name

Delete firewall rule.

gcloud compute firewall-rules delete firewall-name

Cloud Filestore

Cloud Filestore is a managed file service by Google Cloud. It’s a shared file system similar to Amazon’s Elastic File System offering. Users of Cloud Filestore will experience something similar to when using a NAS drive (network attached storage). Filestore is used for both Compute and Kubernetes Engine instances. Unlike EFS where storage is unlimited, you have to specify a storage size when creating a new Filestore.

Create a Filestore:

gcloud beta filestore instances create nfs-server \
    --project=your-project-id \
    --location=your-region \
    --tier=STANDARD \
    --file-share=name="vol1",capacity=1TB \
    --network=name="default",reserved-ip-range="10.0.0.0/29"

Delete a Filestore:

gcloud beta filestore instances delete nfs-server --project=your-project-id --location=your-region

Instance clients can connect to the Filestore using a NFS client.

sudo apt-get -y update
sudo apt-get -y install nfs-common
sudo mkdir /mnt/test
sudo mount 10.0.0.59:/vol1 /mnt/test
sudo chmod go+rw /mnt/test

GCP Attach Detach Disks

Google Cloud Platform just recently released a beta feature called detaching and attaching boot disks. Previously, boot disks were permanently attached to their VM instances. Now you have the ability to detach boot disk from your instance and attach it to another instance without deleting the original instance. You can also replace the boot disks for an instance rather than recreating the entire instance. I’ve tested it on my test account, and it works quite nicely.

I have 2 servers called blue-server and red-server. I’m detaching the disks on blue-server and attaching it to the red-server.

gcloud beta compute instances detach-disk blue-server --disk=blue-server --zone us-central1-c
gcloud beta compute instances attach-disk cyan-server --disk=blue-server --zone us-central1-c
gcloud beta compute instances detach-disk cyan-server --disk=blue-server --zone us-central1-c
gcloud beta compute instances attach-disk blue-server --disk=blue-server --zone us-central1-c

Results:

GCP: Attach and Detach Disks

This new GCP feature is still beta. There might be a few quirks here and there, but overall, it’s a must have feature if you are managing OS.