From 3ed32cf8db344e6bef6ab794e7cf7d664f6aa3df Mon Sep 17 00:00:00 2001 From: David P Date: Tue, 15 Oct 2024 16:20:50 +0200 Subject: [PATCH] GCP notes --- content/docs/devops/gcp/gcloud.md | 84 +++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/content/docs/devops/gcp/gcloud.md b/content/docs/devops/gcp/gcloud.md index d7c3e6e5..9290a372 100644 --- a/content/docs/devops/gcp/gcloud.md +++ b/content/docs/devops/gcp/gcloud.md @@ -40,8 +40,8 @@ gcloud config configurations list ```sh gcloud components list -gcloud components install COMPONENT # COMPONENT: compute, appengine or kubernetes etc.. -gcloud components remove COMPONENT # remove a component from the installation, e.g., gcloud compute +gcloud components install COMPONENT +gcloud components remove COMPONENT gcloud components update ``` @@ -50,5 +50,83 @@ gcloud components update ```sh gcloud projects list gcloud config get-value project -gcloud config set project PROJECT_ID # replace with your Project ID. +gcloud config set project PROJECT_ID +``` + +## Switch account + +```sh +gcloud config configurations list +gcloud config configurations activate ACCOUNT +ls ~/.config/gcloud/configurations +gcloud config configurations describe ACCOUNT +# you can delete non-active configuration +gcloud config configurations delete ACCOUNT +``` + +## Connect to Cloud Shell + +```sh +# create key-pair and connect +gcloud alpha cloud-shell ssh +``` + +## Create a VPC + +In Google Cloud VPC is global, it spans multiple regions. +Subnets are regional and span multiple zones within a region. +This is different from AWS. + +Subnets have unique names across all VPCs. +You need to allow access to the subnet by creating firewall rules. + +```sh +gcloud compute networks create vpc-1 --description "Testing" --subnet-mode custom +gcloud compute firewall-rules create vpc1-fw-allow-ssh --network vpc-1 --allow tcp:22 +gcloud compute networks subnets create vpc1-euw2-1 --network vpc-1 --region europe-west2 --range 10.0.1.0/24 + +gcloud compute networks list +gcloud compute networks subnets list +gcloud compute networks subnets list --network vpc-1 +``` + +Subnets and networks can be deleted if there are no resources running in them. + +```sh +gcloud compute networks subnets delete vpc1-euw2-1 --region europe-west2 +gcloud compute firewall-rules delete vpc1-fw-allow-ssh +gcloud compute networks delete vpc-1 +``` + +## Virtual machines + +Connect to the VM: + +```sh +gcloud compute instances list +gcloud compute ssh vm-1 +``` + +Stop the VM before creating a disk snapshot. + +```sh +# todo +``` + +## Managed instance groups + +- create instance template +- create instance groups and add instances to it + +```sh +# todo +# gcloud compute instance-templates create my-template --image-family centos-7 --machine-type f2-micro +# gcloud compute target-pools create MY_POOL --target-http-proxies PROXY +# gcloud compute instance-groups managed create my-ig --zone us-central1-a —target-size TARGET_SIZE +``` + +## Instance group autoscaling + +```sh +# todo ```