How to Setup Google Cloud CLI/SDK – Beginner Guide
This tutorial will guide you through steps for setting up google cloud SDK on your workstation.
Note: This tutorial will work only on MAC and Linux systems
Step 1: Select the download appropriate sdk package from https://cloud.google.com/sdk/
Step 2: Untar the sdk package.
tar -xvf google-cloud-sdk*
Step 3: Install the sdk using the following command.
Step 3: Follow through the installation instruction and select the required options.
Configuring Google Cloud SDK
Follow the steps given below for configuring the google cloud sdk.
1. Initialize the sdk using the following commands. Y
2. Accept the google login option for logging in to your google cloud account.
To continue, you must log in. Would you like to log in (Y/n)? Y
3. From the browser login to your google cloud account and grant permissions to access google cloud resources.
4. At the command prompt, you will be prompted with options for initial configurations which are self explanatory.
Testing the CLI setup
Now lets run some basic gcloud cli commands to verify the installation.
1. List the credential account.
gcloud auth list
2. List the sdk configuration.
gcloud config list
3. List all the local gcloud configurations and files
4. To list all the gcloud commands, use the following command.
Create an Instance Using CLI
To start with, we will create a instance using the CLI.
1. Get the list of images using the following command.
gcloud compute images list
2. The following command will create a f1 micro Centos instance. You can refer this official documentation for more information on the flags.
gcloud compute instances create devopscube-demo-instance \ --image centos-7-v20170523 \ --image-project centos-cloud --set-machine-type f1-micro --zone us-central1-a
Connecting Instance via ssh
To connect the instance via ssh, just execute the following command. The gcloud command will automatically create the ssh key in your ~/.ssh folder if it doesn’t exist and connects to your instance.
gcloud compute ssh (instance-name)
gcloud compute ssh devopscube-demo-instance
Deleting the Instance
You can delete the created instance using the following command.
gcloud compute instances delete (instance name)
gcloud compute instances delete devopscube-demo-instance