# [[gcloud CLI]] [docs](https://cloud.google.com/sdk/docs/cheatsheet) ![[GCloud CLI.svg]] The GCloud [[CLI]] is the tool for interacting with machines in [[Google Cloud Platform]]. ## Commands ### Authenticate ``` gcloud auth login ``` ### SSH into a compute instance Go to the compute instance. Under the Details tab, click on the dropdown arrow and select *View gcloud command*. ![[gcloud-view-gcloud-command.png]] A command is displayed that you can copy and run on your terminal to gain [[SSH]] access to the instance in question. It looks something like this: ``` gcloud compute ssh --zone "europe-west3-c" "yourls" --project "project-name-123456" ``` where `yourls` is the name of the instance in this case. > [!tip] Connect as root? > To [[Connect to Linux VMs as root|connect to a compute instance as root]], first [[Enabling root access to Linux VM|enable root login]] and then modify the command above to add the user before the VM name like so: > > ```bash > gcloud compute ssh --zone "europe-west3-c" "root@yourls" --project "project-name-123456" > ``` > ### Check version or double-check installation ```bash gcloud version ``` ### Display GCloud details This displays the current gcloud CLI environment details: ```bash gcloud info ``` ### Update GCloud components ```bash gcloud components update ``` ### Get projects list ```bash gcloud projects list ``` ### Get current active project ```bash gcloud config get-value project ``` This will return something like: ```bash project-id-123456 ``` ### List all clusters ```bash gcloud container clusters list ``` ### Create a new cluster ```bash gcloud container clusters create <CLUSTER_NAME> \ --location=<REGION> \ --num-nodes=<NUM_NODES> \ --machine-type=<INSTANCE_TYPE> \ --release-channel=regular \ --workload-pool=<PROJECT_ID>.svc.id.goog \ --enable-ip-alias \ --no-enable-basic-auth \ --no-issue-client-certificate ``` For example: ```bash gcloud container clusters create loki-gcp \ --location=europe-west4 \ --num-nodes=1 \ --machine-type=n2-standard-8 \ --release-channel=regular \ --workload-pool=loki-demo.svc.id.goog \ --enable-ip-alias \ --no-enable-basic-auth \ --no-issue-client-certificate ``` > [!warning]- `num-nodes` for regional nodes > Using regional nodes will automatically start three zones by default, for resilience, so if you set `num_nodes=3` when creating a cluster, you'll actually start 9 nodes total (3 nodes x 3 zones). ### Delete nodes pods in a cluster ```bash gcloud container node-pools delete default-pool \ --cluster=<CLUSTER_NAME> \ --region=<REGION> ``` Note that this doesn't delete the cluster itself. ### Delete cluster ```bash gcloud container clusters delete <CLUSTER_NAME> \ --zone=<REGION> ``` %% # Excalidraw Data ## Text Elements ## Drawing ```json { "type": "excalidraw", "version": 2, "source": "https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/2.1.4", "elements": [ { "id": "4y8R7iOA", "type": "text", "x": 118.49495565891266, "y": -333.44393157958984, "width": 3.8599853515625, "height": 24, "angle": 0, "strokeColor": "#1e1e1e", "backgroundColor": "transparent", "fillStyle": "solid", "strokeWidth": 2, "strokeStyle": "solid", "roughness": 1, "opacity": 100, "groupIds": [], "frameId": null, "roundness": null, "seed": 967149026, "version": 2, "versionNonce": 939059582, "isDeleted": true, "boundElements": null, "updated": 1713723615080, "link": null, "locked": false, "text": "", "rawText": "", "fontSize": 20, "fontFamily": 4, "textAlign": "left", "verticalAlign": "top", "containerId": null, "originalText": "", "lineHeight": 1.2 } ], "appState": { "theme": "dark", "viewBackgroundColor": "#ffffff", "currentItemStrokeColor": "#1e1e1e", "currentItemBackgroundColor": "transparent", "currentItemFillStyle": "solid", "currentItemStrokeWidth": 2, "currentItemStrokeStyle": "solid", "currentItemRoughness": 1, "currentItemOpacity": 100, "currentItemFontFamily": 4, "currentItemFontSize": 20, "currentItemTextAlign": "left", "currentItemStartArrowhead": null, "currentItemEndArrowhead": "arrow", "scrollX": 583.2388916015625, "scrollY": 573.6323852539062, "zoom": { "value": 1 }, "currentItemRoundness": "round", "gridSize": null, "gridColor": { "Bold": "#C9C9C9FF", "Regular": "#EDEDEDFF" }, "currentStrokeOptions": null, "previousGridSize": null, "frameRendering": { "enabled": true, "clip": true, "name": true, "outline": true } }, "files": {} } ``` %%