GCS bucket on NIX based GCP VM

Posted by Amol Dighe on December 7, 2024

Please note we are doing this process on a NIX based VM, same can be done on Ubuntu/Suse or any Linux flavour, just download the respective gscfuse & google-cloud-sdk package

Install gcsfuse in current nix environment

nix-env -iA nixos.gcsfuse

Install gcloud sdk in current nix environment

nix-env -iA nixos.google-cloud-sdk

Authenticate using gcloud

gcloud init

Follow the process mentioned at - https://cloud.google.com/sdk/docs/initializing

Create a local directory on VM

mkdir /application-backup

Create an Service Account & download the Service Account key

Follow the process mentioned at - https://cloud.google.com/iam/docs/service-accounts-create

Attach the Service Account to GCS bucket with Storage Admin privileges

follow the process mentioned at - https://cloud.google.com/iam/docs/attach-service-accounts

Copy the Service Account key (JSON file) on the VM

Use GCSFUSE & Service Account JSON to mount the bucket on the VM

[root@application-server-1:~]# gcsfuse -o allow_other --gid 0 --uid 0 --file-mode 777 --dir-mode 777 --key-file  SERVICE-ACCOUNT-KEY.json application-backup /application-backup
{"time":"21/07/2024 03:54:33.944556","severity":"INFO","msg":"Value of [key-file] resolved from [SERVICE-ACCOUNT-KEY.json] to [/root/SERVICE-ACCOUNT-KEY.json]\n"}
{"time":"21/07/2024 03:54:33.944624","severity":"INFO","msg":"Start gcsfuse/1.4.0 (Go version go1.21.5) for app \"\" using mount point: /application-backup\n"}