Cloud Shell & SDK: Your GCP CLI Toolkit

Whether you're managing GCP resources programmatically or automating workflows, the command-line interface (CLI) is an essential tool. Google provides two main ways to interact via the CLI: Cloud Shell and the Cloud SDK (gcloud). Let's explore both.

1. What is Google Cloud Shell?

Cloud Shell is a browser-based shell preloaded with the gcloud CLI, language SDKs (Java, Python, Go, etc.), and other tools. It runs on a temporary VM in your GCP project and is accessible from anywhere.

To open it, click the terminal icon in the GCP Console header or go to shell.cloud.google.com.

Benefits of Cloud Shell

  • No local installation required
  • Pre-authenticated with your Google account
  • 5GB of persistent storage
  • Works well for quick tasks and demos

2. Installing the Cloud SDK (gcloud CLI)

If you prefer using the CLI locally, install the Cloud SDK, which includes the gcloud tool.

Installation Steps

  • Visit the official page: Cloud SDK Installation Guide
  • Download the installer for your OS (Linux, macOS, Windows)
  • Run the installer and follow the prompts

After installation, run:

gcloud init

This command sets up authentication and selects a project and default configuration.

3. Authenticating with gcloud

The SDK supports multiple authentication flows:

  • gcloud auth login: Opens a browser to authenticate your user account.
  • gcloud auth application-default login: For local development using service credentials.
  • gcloud auth activate-service-account --key-file=KEY.json: For automation with service accounts.

4. Useful gcloud Commands

Project and Configuration

gcloud config list
gcloud config set project PROJECT_ID

Compute Engine

gcloud compute instances list
gcloud compute instances create my-vm --zone=us-central1-a

Cloud Storage

gcloud storage buckets create gs://my-bucket
gcloud storage cp file.txt gs://my-bucket

IAM

gcloud projects get-iam-policy PROJECT_ID
gcloud projects add-iam-policy-binding PROJECT_ID \
  --member="user:you@example.com" --role="roles/viewer"

Help

gcloud help
gcloud <command> --help


Conclusion

The gcloud CLI and Cloud Shell are powerful tools to streamline your GCP workflow. Whether you're deploying services, managing resources, or scripting automations, mastering the CLI is a must for every GCP developer or DevOps engineer.

Post a Comment

0 Comments