From 90e3fe72026f843657e3ddbc515131ce927979ba Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 28 Feb 2025 17:30:02 +0300 Subject: [PATCH] chore(gcloud): improve article --- knowledge base/cloud computing/gcp/cli.md | 68 ++++++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/knowledge base/cloud computing/gcp/cli.md b/knowledge base/cloud computing/gcp/cli.md index 94dabbb..217d42a 100644 --- a/knowledge base/cloud computing/gcp/cli.md +++ b/knowledge base/cloud computing/gcp/cli.md @@ -2,15 +2,56 @@ CLI for the Google Cloud Platform. -## Table of contents - 1. [TL;DR](#tldr) 1. [Further readings](#further-readings) -1. [Sources](#sources) + 1. [Sources](#sources) ## TL;DR +Properties can be set via environment variables following the format `CLOUDSDK_SECTIONNAME_PROPERTYNAME`. + +| Variable | Default | Summary | +| ----------------------------- | --------------------------------------------- | --------------------------- | +| `CLOUDSDK_CONFIG` | `$HOME/.config/gcloud`
`%APPDATA%\gcloud` | CLI configuration directory | +| `CLOUDSDK_CORE_PROJECT` | `` | Project | +| `CLOUDSDK_COMPUTE_ZONE` | `` | Compute zone | +| `CLOUDSDK_ACTIVE_CONFIG_NAME` | `` | Active configuration | + +| Path | Summary | Notes | +| ------------------------------------------------------- | ------------------------------- | ---------------- | +| `$CLOUDSDK_CONFIG` | CLI configuration directory | Must be writable | +| `$CLOUDSDK_CONFIG/configurations/config_default` | Default configuration | | +| `$CLOUDSDK_CONFIG/application_default_credentials.json` | Default application credentials | | + +
+ Setup + ```sh +# Install. +asdf plugin add 'gcloud' && asdf install 'gcloud' 'latest' + +# [optional if one know what they're doing] Initialize. +gcloud init +gcloud init --no-browser +gcloud --configuration 'secondary' init --console-only +``` + +
+ +
+ Usage + +```sh +# Show information about the installation and the active configuration. +gcloud info +gcloud info --format='value(config.paths.global_config_dir)' + +# Show information about gcloud commands and other topics. +gcloud help +gcloud help compute instances create +gcloud cheat-sheet + + # Login. gcloud auth login gcloud … --brief @@ -62,6 +103,16 @@ gcloud config configurations list gcloud config configurations activate "old_profile" +# Update the SDK installation to the latest version. +gcloud components update + +# Install components. +gcloud components install 'skaffold' + +# Remove components. +gcloud components remove 'config-connector' + + # List all project the current user has access to. gcloud projects list --sort-by='projectId' @@ -124,16 +175,17 @@ gcloud config set account "serviceaccount@gcpproject.iam.gserviceaccount.com" \ && gcloud compute instances list ``` +
+ ## Further readings - [Creating and managing projects] - [Install kubectl and configure cluster access] - [`gcloud config configurations`][gcloud config configurations] -## Sources - -All the references in the [further readings] section, plus the following: +### Sources +- [Install the Google Cloud CLI] - [Reference] - [Cheat-sheet] - [How to run gcloud command line using a service account] @@ -148,11 +200,9 @@ All the references in the [further readings] section, plus the following: [creating and managing projects]: https://cloud.google.com/resource-manager/docs/creating-managing-projects [gcloud config configurations]: https://cloud.google.com/sdk/gcloud/reference/config/configurations [install kubectl and configure cluster access]: https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl +[install the google cloud cli]: https://cloud.google.com/sdk/docs/install-sdk [reference]: https://cloud.google.com/sdk/gcloud/reference/ - -[further readings]: #further-readings - [how to change the active configuration profile in gcloud]: https://stackoverflow.com/questions/35744901/how-to-change-the-active-configuration-profile-in-gcloud#35750001 [how to run gcloud command line using a service account]: https://pnatraj.medium.com/how-to-run-gcloud-command-line-using-a-service-account-f39043d515b9