gcloud - Command Line to Manage Google Cloud Account

Опубликовано: 10 Октябрь 2024
на канале: Decode ITES
130
3

#DecodeITeS

The gcloud command-line utility provided by google and part of google SDK to create and manage Google Cloud resources. You can perform a list of operations using gcloud, gcloud is very useful while working scripting some actions or automating some tasks in google cloud.

gcloud Release Levels
The gcloud is part of Google SDK and version of both will be the same. You must ensure that you are using the latest SDK for the latest commands and features. Google gives an option to go beyond this and also leverage you to use alpha & beta versions of Google SDK for upcoming commands in features.
 The gcloud can be divided into 3 types based on release levels:-
General Availability: Publically released version and available by default. Commands & features are fully stable and available for production use.
Beta: Beta version is near to the final release or General Availability version. This is not available by default and users need to install it separately. Commands are functionally complete, but may still have some outstanding issues.
Alpha: Alpha is a very initial phase release where commands are in early release and may change without notice. Similar to the beta version this needs to install separately, not available by default.

gcloud Authorization
There is no doubt that gcloud is a very useful utility and in the demo when we will work with some example, you will also believe it. However, To manage google cloud resource gcloud needs the authorization to connect and perform an action. Google provides 2 types of authorization for gcloud:-
 
User account authorization: It’s useful and recommended when you develop some scripts and planning to execute with your ID or by the individual’s ID who will run it. For this, You just need to run “gcloud init” and based on the credential, you used to log in to google account will be used for access.
Service account authorization: It’s recommended when you are planning to deploy some scripts or automation to execute on a large set of servers or a complete environment. In this case, you need not provide any user ID or password for connectivity. Based on service key authorization you can execute these scripts. For service key authorization, you can download the private key in Jason formatted file from google console and activate it while using. You can use this like:-
gcloud auth activate-service-account --key-file [KEY_FILE]

Properties & Configurations
Properties in gcloud are used to define settings for different gcloud components. Properties govern the behavior of command and impact on components. Like:- selection of the region, zone, project, etc.
Configurations are a set of properties. Implementing or enabling one configuration will apply all properties in one go. Google cloud comes up with default configuration and you can make changes are your need. In case you need different configurations, you can create multiple configurations and choose the appropriate one for your current need.

To list properties of current active configuration - gcloud config list
To list properties of configuration by name - gcloud config configurations describe [NAME]
To make any changes, You can use the “gcloud config set project [PROJECT]” like this.
To list all configurations - gcloud config configurations list
To active required configurations - gcloud config configurations activate [NAME]
To Delete configuration - gcloud config configurations delete [NAME]

Understanding gcloud command syntax
Let's review the gcloud command syntax and understanding it.

gcloud release level (optional) component entity operation positional args flags

Release Level (optional): It refers to release status. As mentioned before, gcloud has 3 types of release levels. To use Beta or Alpha release, you need to mention it explicitly. When you skip it, it will use the default live version.
Component: Component refers to multiple google cloud services like compute, app, Kubernetes, etc.
Entity: Entity refers to the element of the mentioned components that you can change or manage. Example: disks, firewalls, images, instances, regions, zones for compute
Operation: Operation is the action that you want to perform on an entity. Common operations are described, list, create/update, delete/clear, import, export, copy, remove, add, reset, restart, restore, run, and deploy.
Positional args: Positional arguments are required for operation to process command.
Flags: Flags are additional parameters to govern and control the functionality of the complete command. Each operation has it’s own flags and you can check them using short help (-h). Please remember global flags are also applicable here along with this local flag for each operation.