Setting up the Environment of Google Cloud CLI
In the very first step of the “Overview of Google Cloud CLI,” we will look at the installation of Google Cloud CLI.
Step 1. Download the Google Cloud CLI installer.
Step 2. Start the installer, then follow the instructions. Google LLC has signed the installer.
Check the box next to Turn on screen reader mode if you're using a screen reader. This setting instructs gcloud to flatten tables, display progress as a percentage, and use status trackers rather than Unicode spinners.
Step 3. Your operating system must be able to execute a supported version of Python to use Cloud SDK. Python is necessary for Cloud SDK; the accepted versions are Python 2 and Python 3 (recommended versions: 3.5 to 3.8). (2.7.9 or later).
Python 2 and Python 3 are preinstalled on Windows versions of the Cloud SDK by default.
The installer installs all required dependencies, including the required Python version. If necessary, you can use an existing Python installation by unchecking the option to Install Bundled Python, even though Cloud SDK installs and manages Python 3 by default.
Step 4. The installer provides you the choice to launch the Google Cloud CLI shell, set up the gcloud CLI, and create shortcuts for the Start Menu and Desktop after installation is finished. Ensure the options to launch the shell and customize your installation are still chosen. The installer launches the gcloud init command, which also opens a terminal window.
Step 5. The App Engine extensions necessary to deploy an application using gcloud commands are not included in the basic installation. The gcloud CLI component manager can be used to install these components.
Initializing the Google Cloud CLI
In the next step of the "Overview of Google Cloud CLI," we will discuss the initializing of Google Cloud CLI.
1. Start the gcloud CLI using the following command:
gcloud init
2. Accept utilizing your Google user account as a means of authentication:
To continue, you must log in. Would you like to log in (Y/n)? Y
3. To grant access to Google Cloud resources in your browser, sign in with your Google user account when prompted and click Allow.
4. Choose a Google Cloud project from the list of projects where you have Owner, Editor, or Viewer access at the command prompt.
Pick cloud project to use:
[1] [my-project-1]
[2] [my-project-2]
...
Please enter your numeric choice:
5. gcloud init chooses your project if you only have one.
You will be asked to enter a project id, create a new project, or list projects if you have access to more than 200 projects.
This account has a lot of projects! Listing them all can take a while.
[1] Enter a project ID
[2] Create a new project
[3] List projects
Please enter your numeric choice:
gcloud init verifies that you properly completed the setup procedures:
gcloud has now been configured!
You can use [gcloud config] to change more gcloud settings.
Your active configuration is: [default]
6. The accessibility/screen reader property should be enabled to enhance the screen reader experience.
gcloud config set accessibility/screen_reader true
Read about Batch Operating System here.
Commands to view information about your gcloud CLI installation
In this steps of “Overview of Google Cloud CLI,” we will look at the commands to view information about your gcloud CLI.
1. List the accounts whose login information is kept on the local system:
gcloud auth list
The gcloud CLI displays a list of accounts with credentials:
Credentialed Accounts
ACTIVE ACCOUNT
* example-user-1@gmail.com
example-user-2@gmail.com
2. In your current gcloud CLI configuration, list the following properties:
gcloud config list
The gcloud CLI displays the list of properties:
[core]
account = example-user-1@gmail.com
disable_usage_reporting = False
project = example-project
3. View details on your gcloud CLI setup and the current configuration:
gcloud info
An overview of information about your installation is shown via the gcloud CLI. This comprises details about your computer, the installed parts, the running project, and user account, as well as the properties in the current configuration.
4. View details about the installation of your gcloud CLI and the current setup.
gcloud help
To access the help for gcloud compute instances, for instance, create:
gcloud help compute instances create
The Google Cloud CLI shows a help subject with a command explanation, a list of command flags and arguments, and usage examples.
Managing Google Cloud CLI properties
Here, in this part of “Overview of Google Cloud CLI,” we will learn to manage the Google Cloud CLI properties.
Properties are settings that control how the gcloud CLI functions. It specify gcloud CLI preferences like verbosity level, and prompt configuration for gcloud CLI commands.
The account the gcloud CLI uses for permission, the default region to use when interacting with Compute Engine resources, or the choice to disable automatic gcloud CLI component update checks are just a few examples of per-product or per-service settings that can be defined using properties.
Listing Properties in Google Cloud CLI
Run the following instruction to list the properties in the current configuration.
gcloud config list
The following properties are listed by the gcloud CLI:
[compute]
region = us-east1
zone = us-east1-d
[core]
account = user@google.com
disable_usage_reporting = False
project = example-project
[metrics]
command_name = gcloud.config.list
Setting Properties in Google Cloud CLI
Run the following instruction to list the properties in the active configuration.
gcloud config set project PROJECT_ID
You must specify the section, a forward slash, and the property name before you may set any properties that aren't in the core properties section.
gcloud config set compute/zone us-east1-b
The zone name is changed to us-east1-b in the above example.
Environment Variables to Set Properties
Additionally, environment variables can be used to set properties. An environment variable for each property can be used to set it.
The environment variable's name follows the pattern.
CLOUDSDK_SECTION_NAME_PROPERTY_NAME
The compute/zone and core/project properties, for instance, can be configured as follows:
CLOUDSDK_CORE_PROJECT=PROJECT_NAME
CLOUDSDK_COMPUTE_ZONE=ZONE_NAME
Unsetting Properties in Google Cloud CLI
Use this command to remove a setting from the active configuration:
gcloud config unset disable_usage_reporting
Managing Google Cloud CLI components
We will learn how to handle the Google Cloud CLI components in this section of "Overview of Google Cloud CLI."
A component can be a command-line tool, a collection of gcloud CLI instructions at the Alpha or Beta release levels, or a package that provides dependencies needed by a tool in the gcloud CLI. Components are the installable portions of the Google Cloud CLI.
The components that are utilized the most frequently are preinstalled. The gcloud CLI prompts you to install the alpha or beta component if you interactively run a gcloud alpha or gcloud beta command and those components are not already installed. If you answer "yes," the component is installed, and the command is then executed.
Depending on your requirements, you can list, install, update, and remove gcloud CLI components.
Listing Components in Google Cloud CLI
To get a list of the installed and available parts, run the following command.
gcloud components list
Installing Components in Google Cloud CLI
For your gcloud CLI installation to be updated with a component, run the following command:
gcloud components install [COMPONENT-ID]
The selected component is installed by the gcloud CLI.
Updating Components in Google Cloud CLI
To update all installed components to the most recent gcloud CLI release: run the following command:
gcloud components update
The gcloud CLI upgrades all the installed components if you have an earlier version installed.
Use the following command to go back to the specified version if you need to restore to a previously known good version and install the gcloud CLI directly:
gcloud components update --version VERSION
Removing Components in Google Cloud CLI
To delete a component that has been identified by its ID, use the following command:
gcloud components remove [COMPONENT-ID]
Also see, wc command in linux
Scripting Google Cloud CLI Commands
In this part of “Overview of Google Cloud CLI,” we will learn to use Google Cloud commands using Scripts.
Google Cloud CLI Commands can be run using scripts and other automation.
Authorization techniques need to be taken into account while scripting with the Google Cloud CLI. The gcloud CLI offers two choices:
- User account authorization
- Service account authorization
User Account Authorization
User account permission is advised if you are using a script or other automation on a single machine.
To approve access and carry out additional typical gcloud CLI setup procedure:
gcloud init
Service Account Authorization
Service account permission is used when deploying a script or other automation across computers in a production setting.
Additionally, this is the suggested authorization technique if you are using Google Cloud CLI commands on a virtual machine instance where all users have root access.
Use an existing service account or create a new one on the Service Accounts page to use service account authorization: Go to the Service Accounts page.
Select Manage Keys from the service account's action menu to generate and download the corresponding private key as a JSON-formatted key file.
To run the service account authorization, use the following command:
gcloud auth activate-service-account --key-file [KEY_FILE]
Using gcloud compute ssh, which handles authentication, you can SSH into your VM instance. Using gcloud compute config-ssh, SSH configuration files can be set up.
Google Cloud CLI Basic Commands
In this last part of "Overview of Google Cloud CLI," we will look at the primary commands to work with Google Cloud CLI fastly.
Getting Started with Google Cloud CLI
- gcloud init: This command work for setup, permissions, and configuration of the Google Cloud CLI.
- gcloud version: It shows the version and installed components.
- gcloud components install: It installs the required elements.
- gcloud components update: It gets the most recent version of the Google Cloud CLI.
- gcloud config set project: It chooses a Google Cloud project by default to work on.
-
gcloud info: It shows current information about the gcloud CLI environment.
Help with Google Cloud CLI
- gcloud help: It is used to find specific phrases and search the Google Cloud CLI reference documents.
- gcloud feedback: It is used to provide feedback to the Google Cloud CLI team.
-
gcloud topic: It helps in the documentation for gcloud subjects like accessibility, filtering, and formatting.
Also see, How to Check Python Version in CMD
Frequently Asked Questions
Explain Serverless computing.
In serverless computing, the cloud service provider runs a server in the cloud and controls the distribution of resources on a flexible basis. The provider provides the infrastructure, so the user doesn't have to worry about the hardware and can focus on their business.
How well do you know to Google Cloud APIs?
The main purpose of APIs is to automate the workflow using the language of your choice. APIs make it possible to communicate with different Google services and also make it easier for them to be integrated with other services. It can also be described as a gateway that gives consumers access to different software services and direct and indirect cloud infrastructure.
What is Cloud Scheduler?
An enterprise-level cron task scheduler that is completely managed is called Cloud Scheduler. It enables you to schedule practically any process, including batch, large data, cloud infrastructure activities, and more.
Conclusion
Congratulations on finishing the blog! We have discussed the overview of Google Cloud CLI. We further discussed the installation, initialization, and managing of components and properties in Google Cloud CLI.
If you want to explore more blogs on this topic, please follow these blogs especially curated for readers like you- Cloud Computing, Cloud Computing Technologies, Cloud Server, and Cloud Computing Infrastructure.
Please refer to our guided pathways on Code studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses, and use the accessible sample exams and questions as a guide. For placement preparations, look at the interview experiences and interview package.
Please do upvote our blogs if you find them helpful and informative!
Happy learning!