gcloud installation and configuration
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have listed all the available services under GCP.
https://cloudaffaire.com/google-cloud-platform-services/
GCP provides multiple ways to interact with the above services. You can use google cloud console, Cloud SDK, API, etc. to create and manage resources in GCP. In this blog post, we will discuss gcloud, a command-line interface provided by google to interact with GCP resources.
What is gcloud?
The gcloud command-line interface is a tool that provides the primary CLI to Google Cloud Platform. You can use this tool to perform many common platform tasks either from the command-line or in scripts and other automations.
The gcloud CLI is a part of the Google Cloud SDK. You must download and install the SDK on your system and initialize it before you can use the gcloud command-line tool.
By default, the SDK installs those gcloud CLI commands that are at the General Availability level only. Additional functionality is available in SDK components named alpha and beta. These components allow you to use the gcloud CLI to work with Google Cloud Bigtable, Google Cloud Dataflow and other parts of the Cloud Platform at earlier release levels than General Availability.
Google provides gcloud interface directly in your browser which is preinstalled and preconfigured. To access your gcloud interface from browser you can simply login to your cloud console and click on ‘Activate cloud shell’.
But if you want to use gcloud from a remote system or from a compute instance, you need to install and configure the gcloud tool.
gcloud installation and configuration:
Prerequisite for gcloud:
- A GCP account with at least one project
- A service account with proper access to the project.
Step 1: Create a service account for gcloud
Login to the GCP console and click on ‘IAM & admin’ > ‘Service accounts’
Click ‘CREATE SERVICE ACCOUNT’
Provide a name to your service account and click ‘CREATE’
Provide access to your project to the service account
Create a key file and click ‘DONE’
Note: One key file with .json extension will be downloaded automatically, keep this file in a safe location. We will use this key file during gcloud configuration.
Step 2: gcloud installation and configuration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
############################################### ## GCP gcloud installation and configuration ## ############################################### ## Prerequisite: Python, GCP service account key ## Get the latest gcloud package from: https://cloud.google.com/sdk/docs/quickstarts ################## ## Installation ## ################## ## OS: Linux ## ## download the Linux 64-bit archive file from your command-line curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-274.0.0-linux-x86_64.tar.gz ## Extract the archive tar zxvf google-cloud-sdk-274.0.0-linux-x86_64.tar.gz google-cloud-sdk && \ rm -rf google-cloud-sdk-274.0.0-linux-x86_64.tar.gz ## Use the install script to add Cloud SDK tools to your path. ./google-cloud-sdk/install.sh ## OS: Debian and Ubuntu ## ## Add the Cloud SDK distribution URI as a package source echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list ## Import the Google Cloud Platform public key curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - ## Update the package list and install the Cloud SDK sudo apt-get update && sudo apt-get install google-cloud-sdk ## OS: RedHat and CentOS ## ## Update YUM with Cloud SDK repo information: sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM [google-cloud-sdk] name=Google Cloud SDK baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg EOM # The indentation for the 2nd line of gpgkey is important. ## Install the Cloud SDK sudo yum install google-cloud-sdk ## OS: MAC ## ## download the Linux 64-bit archive file from your command-line curl -o https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-274.0.0-darwin-x86_64.tar.gz ## Extract the archive tar zxvf google-cloud-sdk-274.0.0-darwin-x86_64.tar.gz google-cloud-sdk && \ rm -rf google-cloud-sdk-274.0.0-darwin-x86_64.tar.gz ## Use the install script to add Cloud SDK tools to your path. ./google-cloud-sdk/install.sh ## OS: Windows ## ## Download and install windows installer using below link https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe ################### ## Configuration ## ################### ## Check your gcloud version gcloud --version ## Copy the key file that you have downloaded during service account creation ## Set gcloud authentication using the service account gcloud auth activate-service-account \ --key-file= ## If API is not enabled for your project, you will get an notification, select yes to activate API for your project ## Imporve gcloud UI (Optional) gcloud config set accessibility/screen_reader true ## Getting help gcloud help gcloud help projects ## gcloud command syntax: https://cloud.google.com/sdk/gcloud/reference/ ## gcloud GROUP | COMMAND [--account=ACCOUNT] [--billing-project=BILLING_PROJECT] ## [--configuration=CONFIGURATION] [--flags-file=YAML_FILE] [--flatten=[KEY,…]] ## [--format=FORMAT] [--help] [--project=PROJECT_ID] [--quiet, -q] ## [--verbosity=VERBOSITY; default="warning"] [--version, -v] [-h] ## [--impersonate-service-account=SERVICE_ACCOUNT_EMAIL] [--log-http] ## [--trace-token=TRACE_TOKEN] [--no-user-output-enabled] |
Hope you have enjoyed this blog post.
To get more details on gcloud and Google cloud SDK, please refer below GCP documentation
https://cloud.google.com/sdk/docs/
https://cloud.google.com/sdk/gcloud/reference/