• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

gcp

GCP Terraform Second Drive

February 4, 2022 by Ulysses

How to add a second drive on GCP Compute Engine using Terraform.

provider "google" {
  project = "your-project-id"
  zone    = "us-central1-c"
}
 
resource "google_compute_disk" "data-drive" {
  name = "data-drive"
  type = "pd-standard"
  zone = "us-central1-c"
  size = "20"
}
 
resource "google_compute_attached_disk" "attach-data-drive" {
  count    = 1
  disk     = google_compute_disk.data-drive.id
  instance = google_compute_instance.test.id
}
 
resource "google_compute_instance" "test" {
  name         = "test"
  machine_type = "e2-micro"
 
  boot_disk {
    initialize_params {
      image = "rocky-linux-cloud/rocky-linux-8"
    }
  }
 
  scheduling {
    preemptible       = true
    automatic_restart = false
  }
  network_interface {
    network = "default"
    access_config {
    }
  }
}

provider "google" { project = "your-project-id" zone = "us-central1-c" } resource "google_compute_disk" "data-drive" { name = "data-drive" type = "pd-standard" zone = "us-central1-c" size = "20" } resource "google_compute_attached_disk" "attach-data-drive" { count = 1 disk = google_compute_disk.data-drive.id instance = google_compute_instance.test.id } resource "google_compute_instance" "test" { name = "test" machine_type = "e2-micro" boot_disk { initialize_params { image = "rocky-linux-cloud/rocky-linux-8" } } scheduling { preemptible = true automatic_restart = false } network_interface { network = "default" access_config { } } }

Filed Under: Cloud Tagged With: compute, drive, gcp, second, terraform, vm

GCP Create Scheduled Snapshots

February 2, 2022 by Ulysses

How to create scheduled snapshots in GCP.

gcloud compute resource-policies create snapshot-schedule hourly \
--description "my hourly schedule" \
--max-retention-days 7 \
--start-time 00:00 \
--hourly-schedule 1 \
--region us-central1 \
--on-source-disk-delete keep-auto-snapshots \
--storage-location US

gcloud compute resource-policies create snapshot-schedule hourly \ --description "my hourly schedule" \ --max-retention-days 7 \ --start-time 00:00 \ --hourly-schedule 1 \ --region us-central1 \ --on-source-disk-delete keep-auto-snapshots \ --storage-location US

Add snapshot schedule to a disk.

gcloud compute disks add-resource-policies disk-name \
--resource-policies hourly \
--zone us-central1-a

gcloud compute disks add-resource-policies disk-name \ --resource-policies hourly \ --zone us-central1-a

gcloud compute disks create disk-name \
--resource-policies hourly \
--zone us-central1-a

gcloud compute disks create disk-name \ --resource-policies hourly \ --zone us-central1-a

List snapshot schedules.

gcloud compute resource-policies list

gcloud compute resource-policies list

Describe snapshot schedule.

gcloud compute resource-policies describe hourly

gcloud compute resource-policies describe hourly

Filed Under: Cloud Tagged With: add, create, gcp, list, schedule, snapshot

GCP Compute add startup-script to metadata

February 2, 2022 by Ulysses

How to add a startup-script to metadata. The script executes every time VM is started.

gcloud compute instances add-metadata instance-name \
--project your-project-id \
--zone us-central1-c \
--metadata=startup-script='#! /bin/bash
sudo -i
echo "Time: $(date)" >> /tmp/date.txt'

gcloud compute instances add-metadata instance-name \ --project your-project-id \ --zone us-central1-c \ --metadata=startup-script='#! /bin/bash sudo -i echo "Time: $(date)" >> /tmp/date.txt'

Filed Under: Cloud Tagged With: add, boot, compute, gcp, metadata, startup-script

GCP CVS Mount Instructions

January 28, 2022 by Ulysses

Here are the mount instructions for NFS and SMB drives for GCP Netapp CVS.

NFS

sudo yum install -y nfs-utils
sudo apt-get install nfs-common
sudo mkdir /condescending-sharp-hugle
sudo mount -t nfs -o rw,hard,rsize=65536,wsize=65536,vers=3,tcp 10.49.253.6:/condescending-sharp-hugle /condescending-sharp-hugle

sudo yum install -y nfs-utils sudo apt-get install nfs-common sudo mkdir /condescending-sharp-hugle sudo mount -t nfs -o rw,hard,rsize=65536,wsize=65536,vers=3,tcp 10.49.253.6:/condescending-sharp-hugle /condescending-sharp-hugle

SMB

Mapping your network drive
1. Click the Start button and then click on Computer.
2. Click Map Network Drive.
3. In the Drive list, click any available drive letter.
4. In the folder box, type \\shared.mydomain.com\myshare.
To connect every time you log on to your computer, select the Reconnect at sign-in check box.
\\shared.mydomain.com\myshare
5. Click Finish.

Mapping your network drive 1. Click the Start button and then click on Computer. 2. Click Map Network Drive. 3. In the Drive list, click any available drive letter. 4. In the folder box, type \\shared.mydomain.com\myshare. To connect every time you log on to your computer, select the Reconnect at sign-in check box. \\shared.mydomain.com\myshare 5. Click Finish.

Filed Under: Cloud, Linux Tagged With: cvs, gcp, instructions, mount, netapp, nfs, smb

GCP List Keys of Service Account

January 26, 2022 by Ulysses

How to list all the keys of a GCP service account.

gcloud iam service-accounts keys list \
--iam-account=your-service-account@your-project-id.iam.gserviceaccount.com \
--project project-id

gcloud iam service-accounts keys list \ --iam-account=your-service-account@your-project-id.iam.gserviceaccount.com \ --project project-id

Result. Keys are redacted.

KEY_ID                                    CREATED_AT            EXPIRES_AT            DISABLED
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  2022-01-10T19:21:18Z  2022-01-26T19:21:18Z
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  2022-01-19T00:06:49Z  2022-02-04T00:06:49Z

KEY_ID CREATED_AT EXPIRES_AT DISABLED xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2022-01-10T19:21:18Z 2022-01-26T19:21:18Z xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2022-01-19T00:06:49Z 2022-02-04T00:06:49Z

Filed Under: Cloud Tagged With: gcp, keys, list, service account

Metadata URL

January 15, 2022 by Ulysses

Here’s the metadata URLs for both AWS and GCP.

curl http://169.254.169.254/computeMetadata/v1/ -H "Metadata-Flavor: Google"
curl http://169.254.169.254/latest/meta-data/

curl http://169.254.169.254/computeMetadata/v1/ -H "Metadata-Flavor: Google" curl http://169.254.169.254/latest/meta-data/

Filed Under: Cloud Tagged With: aws, gcp, metadata, url

GCP List Disk Types

December 22, 2021 by Ulysses

To list all disk types available in your project in all regions. Result is truncated.

$ gcloud compute disk-types list
NAME         ZONE                       VALID_DISK_SIZES
pd-balanced                             10GB-65536GB
pd-ssd                                  10GB-65536GB
pd-standard                             200GB-65536GB
pd-balanced                             10GB-65536GB
...

$ gcloud compute disk-types list NAME ZONE VALID_DISK_SIZES pd-balanced 10GB-65536GB pd-ssd 10GB-65536GB pd-standard 200GB-65536GB pd-balanced 10GB-65536GB ...

To list a specific region, use the filter option.

$ gcloud compute disk-types list --filter="zone~'us-central1'"
NAME         ZONE           VALID_DISK_SIZES
pd-balanced  us-central1-a  10GB-65536GB
pd-extreme   us-central1-a  500GB-65536GB
pd-ssd       us-central1-a  10GB-65536GB
pd-standard  us-central1-a  10GB-65536GB
pd-balanced  us-central1-b  10GB-65536GB
pd-extreme   us-central1-b  500GB-65536GB
pd-ssd       us-central1-b  10GB-65536GB
pd-standard  us-central1-b  10GB-65536GB
pd-balanced  us-central1-c  10GB-65536GB
pd-extreme   us-central1-c  500GB-65536GB
pd-ssd       us-central1-c  10GB-65536GB
pd-standard  us-central1-c  10GB-65536GB
pd-balanced  us-central1-f  10GB-65536GB
pd-extreme   us-central1-f  500GB-65536GB
pd-ssd       us-central1-f  10GB-65536GB
pd-standard  us-central1-f  10GB-65536GB
pd-balanced  us-central1-d  10GB-65536GB
pd-extreme   us-central1-d  500GB-65536GB
pd-ssd       us-central1-d  10GB-65536GB
pd-standard  us-central1-d  10GB-65536GB

$ gcloud compute disk-types list --filter="zone~'us-central1'" NAME ZONE VALID_DISK_SIZES pd-balanced us-central1-a 10GB-65536GB pd-extreme us-central1-a 500GB-65536GB pd-ssd us-central1-a 10GB-65536GB pd-standard us-central1-a 10GB-65536GB pd-balanced us-central1-b 10GB-65536GB pd-extreme us-central1-b 500GB-65536GB pd-ssd us-central1-b 10GB-65536GB pd-standard us-central1-b 10GB-65536GB pd-balanced us-central1-c 10GB-65536GB pd-extreme us-central1-c 500GB-65536GB pd-ssd us-central1-c 10GB-65536GB pd-standard us-central1-c 10GB-65536GB pd-balanced us-central1-f 10GB-65536GB pd-extreme us-central1-f 500GB-65536GB pd-ssd us-central1-f 10GB-65536GB pd-standard us-central1-f 10GB-65536GB pd-balanced us-central1-d 10GB-65536GB pd-extreme us-central1-d 500GB-65536GB pd-ssd us-central1-d 10GB-65536GB pd-standard us-central1-d 10GB-65536GB

To a list a specific region and local SSDs only.

gcloud compute disk-types list --filter="zone~'us-central1' AND name~'local-'"
NAME       ZONE           VALID_DISK_SIZES
local-ssd  us-central1-a  375GB-375GB
local-ssd  us-central1-b  375GB-375GB
local-ssd  us-central1-c  375GB-375GB
local-ssd  us-central1-f  375GB-375GB
local-ssd  us-central1-d  375GB-375GB

gcloud compute disk-types list --filter="zone~'us-central1' AND name~'local-'" NAME ZONE VALID_DISK_SIZES local-ssd us-central1-a 375GB-375GB local-ssd us-central1-b 375GB-375GB local-ssd us-central1-c 375GB-375GB local-ssd us-central1-f 375GB-375GB local-ssd us-central1-d 375GB-375GB

Filed Under: Cloud Tagged With: disks, filter, gcp, list, region, type

GCS Fuse

December 21, 2021 by Ulysses

GCS Fuse allows you to mount a Google bucket as a file system. It’s similar to S3FS.

Setup repo

sudo tee /etc/yum.repos.d/gcsfuse.repo > /dev/null <<EOF
[gcsfuse]
name=gcsfuse (packages.cloud.google.com)
baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

sudo tee /etc/yum.repos.d/gcsfuse.repo > /dev/null <<EOF [gcsfuse] name=gcsfuse (packages.cloud.google.com) baseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=0 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg EOF

Yum install

sudo yum install gcsfuse

sudo yum install gcsfuse

Login to GCP and mount. Run as a user and not root.

gcloud auth login
gcsfuse my-bucket /path/to/mount

gcloud auth login gcsfuse my-bucket /path/to/mount

Unmount

fusermount -u /path/to/mount

fusermount -u /path/to/mount

Filed Under: Cloud, Linux Tagged With: bucket, fuse, gcp, gcs, mount, s3fs, umount

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Interim pages omitted …
  • Go to page 15
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2012–2022