Getting started with Gcloud

Getting started with Gcloud

ยท

3 min read

  • Command line interface to interact with Google Cloud Resources.

  • Most GCP services can be managed from CLI using GCloud.

    • Compute Engine Virtual Machines

    • Managed Instance Groups

    • Databases

    • and .... many more

  • We can create/delete/update/read existing resources and perform actions like deployments as well.

  • (REMEMBER) Some GCP services have specific CLI tools:

    • Cloud Storage- gsutil

    • Cloud BigQuery- bq

    • Cloud BigTable- cbt

    • Kubernetes- kubectl(in addition to GCloud which is used to manage clusters)

Installation

  • GCloud is a part of Google Cloud SDK.

  • We can also use Gcloud on Cloud Shell

gcloud --version
  • Initialize Gcloud

    • Initialize or reinitialize gcloud

    • Authorize gcloud to use your user account credentials

    • Setup configuration

gcloud init
  • List all properties of the active configuration

    • region

    • zone

    • [core]

      • account

      • project

gcloud config list

Understanding command structure in Gcloud to play with services

gcloud GROUP SUBGROUP ACTION ...
  • GROUP:

    • config or compute or container or dataflow or functions or iam or....

      • which service group are you playing with.
  • SUBGROUP:

    • Instances or images or instance templates or machine-types or regions or zones.

      • Which subgroup of the service do you want to play with?
  • ACTION:

    • Create or list or start or stop or describe or...

      • What do you want to do?

Example:

  • List all GCP Compute Engine instances

      gcloud compute instances list
    
    • GROUP: compute

    • SUBGROUP: instances

    • ACTION: list

  • Create a new instance

      gcloud compute instances create my-first-instance
    
  • Describe a specific instance[all details around a compute instance]

      gcloud compute instances describe my-first-instance
    
  • Delete a instance

      gcloud compute instances delete my-first-instance
    

    Other examples

      gcloud compute regions list
      gcloud compute zones list
      gcloud compute machine-types list
      gcloud compute machine-types list --filter="zone:us-central1-b"
    

    Important things to remember

    • Cloud Shell is backed by a VM instance(automatically provisioned by Google Cloud when you launch Cloud Shell)

      • 5 GB of free persistent disk storage is provided as your $HOME directory

      • Prepackaged with the latest version of Cloud SDK, docker, etc.

      • (Remember) Files in your home directory persist between sessions(scripts, user configuration files like .bashrc and .vimrc, etc)

      • The instance is terminated if you are inactive for more than 20 minutes.

        • Any modifications that you made to it outside your $HOME will be lost.
      • (REMEMBER) After 120 days of inactivity, even your $HOME directory is deleted.

    • Cloud Shell can be used to SSH into virtual machines using their private IP addresses.

Did you find this article valuable?

Support KubeKode Blogs by becoming a sponsor. Any amount is appreciated!

ย