Common Google Cloud [gcloud](https://cloud.google.com/sdk/gcloud) Commands
Once you begin your Google Cloud journey, either towards certification or for personal projects, you’ll find yourself dropping down to the command line(via the cloud shell or on your local machine) to use the very powerful and flexible gcloud CLI tool. Here are common and useful gcloud commands.
The gcloud tool provides very useful feedback when you get a command wrong. Its documentation (via gcloud
Initialize gcloud
gcloud init
#this will allow you to authenticate and authorize via the browser
Log out or revoke gcloud access
gcloud auth revoke [email protected]
#removes access to engineer1@gmail
Get information about gcloud installed environment
gcloud info
#gcloud versioni, log path, python version, git version, account, project etc...
View Your Project ID
gcloud config list project
View list of authenticated accounts
gcloud auth list
#displays the list of authenticated email accounts on the machine
View Your Authenticated Account
gcloud config list account
#displays the authenticated email address
List available projects
gcloud projects list
#Lists all projects available to the authenticated account
View Your Project Metadata(eg. default region and zone)
gcloud compute project-info --project=PROJECTID describe
#NOTE: If default region and zone are not configured this output will be blank
Set a default region for gcloud
gcloud config set compute/region us-central1
#the gcloud tool will automatically use this region when none is specified
Set a default zone for gcloud
gcloud config set compute/region us-central1-c
#the gcloud tool will automatically use this zone when none is specified
Enable a service
gcloud services enable name-of-service
#the gcloud tool will automatically use this zone when none is specified
List enabled services in a project
gcloud services list #implies --enabled
List all available services
gcloud services list --available
#this includes the services that are also enabled for the project
List available compute instances
gcloud compute instances list
Create a compute engine instance with a specific machine types
gcloud compute instances create name-of-instance --machine-type=f1-micro
List available compute engine machine types
gcloud compute machine-types list
List available GKE clusters
gcloud container clusters list
Generate .kubeconfig for kubectl in order to manage a cluster on GKE
gcloud container clusters get-credentials name-of-cluster --zone=NONE
#you'll need to do this when the cluster is created on different machine
#and the corresponding kubeconfi entries
#are not avaialable on your local machine(or cloud shell)
List available docker images in project’s Container Registry
gcloud container images list
View all availables tags for a container image
gcloud container images list-tags IMAGE_NAME
If you find this guide useful, kindly share it with your friends via email, social media so that they can also benefit.
If you need assistance with any of the following steps contact me
- SKS
Check out our other guides
Comments
comments powered by Disqus