Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Archives for gcloud

January 14, 2021

Create Instance With Alias IP

How to create an instance from a snapshot with alias IP and reserved IPs.

#!/bin/bash
gcloud beta compute instances create jump-server \
--network-interface=aliases=10.128.1.0/24,private-network-ip=jump-server,subnet=default \
--machine-type=n1-standard-1 \``
--network-tier=PREMIUM \
--maintenance-policy=MIGRATE \
--service-account=xxxxxxxxxxxxx-compute@developer.gserviceaccount.com \
--tags=int-webserver \
--image=debian-10-buster-v20201216 \
--image-project=debian-cloud \
--boot-disk-size=20GB \
--boot-disk-type=pd-standard \
--boot-disk-device-name=jump-server-1 \
--no-shielded-secure-boot \
--shielded-vtpm \
--shielded-integrity-monitoring \
--labels=name=jump-server \
--reservation-affinity=any \
--zone=us-central1-a \
--project=airy-totality-151318

#!/bin/bash gcloud beta compute instances create jump-server \ --network-interface=aliases=10.128.1.0/24,private-network-ip=jump-server,subnet=default \ --machine-type=n1-standard-1 \`` --network-tier=PREMIUM \ --maintenance-policy=MIGRATE \ --service-account=xxxxxxxxxxxxx-compute@developer.gserviceaccount.com \ --tags=int-webserver \ --image=debian-10-buster-v20201216 \ --image-project=debian-cloud \ --boot-disk-size=20GB \ --boot-disk-type=pd-standard \ --boot-disk-device-name=jump-server-1 \ --no-shielded-secure-boot \ --shielded-vtpm \ --shielded-integrity-monitoring \ --labels=name=jump-server \ --reservation-affinity=any \ --zone=us-central1-a \ --project=airy-totality-151318

The default command uses –private-network-ip and –subnet options separately.

--private-network-ip 10.0.0.24 \
--subnet=default \

--private-network-ip 10.0.0.24 \ --subnet=default \

But when dealing with aliases, reserved IPs and subnets, use a single –network-interface option instead.

--network-interface=aliases=10.128.1.0/24,private-network-ip=jump-server,subnet=default \

--network-interface=aliases=10.128.1.0/24,private-network-ip=jump-server,subnet=default \

January 10, 2021

GCP Manually Move Instance

Here’s how to move a VM instance from one zone to another. Moving an instance will involve destroying the instance from the source zone, and then recreating a replacement instance in the destination zone. To make the move easier, we will use a machine image to recreate the instance. We will also take advantage of the compute and IP address reservations to guarantee that we use the same IP address machine type. Some large machine types are hard to come by.

Get a list of compute and IP reservations.

gcloud compute addresses list
gcloud compute reservations list

gcloud compute addresses list gcloud compute reservations list

Make reservations.

gcloud compute addresses create centos-ip-reservation --addresses 10.128.15.216 --region us-central1 --subnet default
gcloud compute reservations create centos-us-central1-b --machine-type=n1-standard-1 --vm-count=1 --zone us-central1-b

gcloud compute addresses create centos-ip-reservation --addresses 10.128.15.216 --region us-central1 --subnet default gcloud compute reservations create centos-us-central1-b --machine-type=n1-standard-1 --vm-count=1 --zone us-central1-b

Create a machine image.

gcloud compute instances stop centos
gcloud beta compute machine-images create centos-image-00 --source-instance centos

gcloud compute instances stop centos gcloud beta compute machine-images create centos-image-00 --source-instance centos

Delete original instance.

gcloud compute instances delete centos

gcloud compute instances delete centos

Create an instance from image in the new zone. Use the compute and ip reservations previously made.

gcloud beta compute instances create centos \
--no-address \
--private-network-ip 10.128.15.216 \
--source-machine-image=centos-image-00 \
--subnet=https://www.googleapis.com/compute/v1/projects/airy-totality-151318/regions/us-central1/subnetworks/default \
--machine-type=n1-standard-1 \
--reservation-affinity=any \
--reservation=centos-us-central1-b \
--zone=us-central1-b

gcloud beta compute instances create centos \ --no-address \ --private-network-ip 10.128.15.216 \ --source-machine-image=centos-image-00 \ --subnet=https://www.googleapis.com/compute/v1/projects/airy-totality-151318/regions/us-central1/subnetworks/default \ --machine-type=n1-standard-1 \ --reservation-affinity=any \ --reservation=centos-us-central1-b \ --zone=us-central1-b

Finally, clean it up once you are done.

gcloud compute instances delete centos --zone us-central1-b
gcloud compute addresses delete centos-ip-reservation 
gcloud compute reservations delete centos-us-central1-b --zone us-central1-b
gcloud beta compute machine-images delete centos-image-00

gcloud compute instances delete centos --zone us-central1-b gcloud compute addresses delete centos-ip-reservation gcloud compute reservations delete centos-us-central1-b --zone us-central1-b gcloud beta compute machine-images delete centos-image-00

October 29, 2020

GCP SSL Certificates

Here’s how to create a regional SSL Certificate.

gcloud compute ssl-certificates create my-ssl-cert \
--description "describe ssl certificate" \
--domains=domain1.com,domain2.com \
--certificate=cert.pem \
--private-key=private.key \
--region=us-central1

gcloud compute ssl-certificates create my-ssl-cert \ --description "describe ssl certificate" \ --domains=domain1.com,domain2.com \ --certificate=cert.pem \ --private-key=private.key \ --region=us-central1

List the SSL certificates.

gcloud compute ssl-certificates list --project=project-id

gcloud compute ssl-certificates list --project=project-id

Describe the SSL certificate.

gcloud compute ssl-certificates describe my-ssl-cert \
--region=us-central1 \
--project=project-id

gcloud compute ssl-certificates describe my-ssl-cert \ --region=us-central1 \ --project=project-id

Delete SSL certificate.

gcloud compute ssl-certificates delete my-ssl-cert \
--region=us-central1 \
--project=project-id

gcloud compute ssl-certificates delete my-ssl-cert \ --region=us-central1 \ --project=project-id

September 29, 2020

GCP Create Internal IP Reservation

Here’s how to create an internal IP reservation in GCP.

gcloud compute addresses create my-private-ip-reservation \
--addresses 10.128.0.15 \
--region us-central1 \
--subnet default \
--project project-id

gcloud compute addresses create my-private-ip-reservation \ --addresses 10.128.0.15 \ --region us-central1 \ --subnet default \ --project project-id

To list your reserved IPs.

gcloud compute addresses list \
--project project-id

gcloud compute addresses list \ --project project-id

September 12, 2020

Extend Regional Persistent Disks

Here’s the command to extend your regional persistent disks.

gcloud compute disks resize disk-name \
--size 100 \
--project project-id \
--region us-central1

gcloud compute disks resize disk-name \ --size 100 \ --project project-id \ --region us-central1

Display the updated disk details.

gcloud compute disks list \
--filter="name=disk-name" \
--project project-id

gcloud compute disks list \ --filter="name=disk-name" \ --project project-id

  • 1
  • 2
  • 3
  • Next Page »
  • Cloud
  • Linux
  • Git

Copyright © 2012–2021