
Learn how to install and configure Google Chrome Remote Desktop on Ubuntu 24.04 with this comprehensive step-by-step guide. Ensure secure and efficient remote access to
Master the top 10 Google Cloud CLI commands every DevOps engineer should know. Boost productivity with real-world examples, command tables, and automation tips.
In the fast-paced world of DevOps, efficiency and automation are paramount. Google Cloud’s Command-Line Interface (CLI), gcloud
, is an indispensable tool for DevOps engineers, enabling them to manage resources, automate workflows, and streamline operations. This comprehensive guide delves into the top 10 gcloud
commands every DevOps engineer should master, complete with practical examples and best practices.
1. Setting Up Your Project |
Before diving into resource management, ensure you’re working within the correct Google Cloud project. The following command sets your active project:
gcloud config set project PROJECT_ID
Replace PROJECT_ID
with your actual project ID. To verify your current configuration, use:
gcloud config list
2. Managing Compute Resources |
Google Compute Engine (GCE) allows you to run virtual machines (VMs) on Google Cloud. Here are some essential commands:
Command | Description |
---|---|
gcloud compute instances list | Lists all VM instances |
gcloud compute instances create INSTANCE_NAME --zone=ZONE | Creates a new VM instance |
gcloud compute instances delete INSTANCE_NAME --zone=ZONE | Deletes a VM instance |
Example:
gcloud compute instances create my-vm --zone=us-central1-a
3. Handling Cloud Storage |
Google Cloud Storage is ideal for storing and retrieving any amount of data. Use the gsutil
tool for storage operations:
Command | Description |
---|---|
gsutil mb gs://BUCKET_NAME | Creates a new bucket |
gsutil cp FILE gs://BUCKET_NAME/ | Uploads a file to a bucket |
gsutil rm gs://BUCKET_NAME/OBJECT_NAME | Deletes an object from a bucket |
Example:
gsutil cp myfile.txt gs://my-bucket/
4. Interacting with Google Kubernetes Engine (GKE) |
GKE simplifies the deployment and management of containerized applications. Key gcloud
commands include:
Command | Description |
---|---|
gcloud container clusters list | Lists all GKE clusters |
gcloud container clusters create CLUSTER_NAME --zone=ZONE | Creates a new GKE cluster |
gcloud container clusters get-credentials CLUSTER_NAME --zone=ZONE | Configures kubectl to use the cluster |
Example:
gcloud container clusters create my-cluster --zone=us-central1-a
gcloud container clusters get-credentials my-cluster --zone=us-central1-a
5. Configuring Identity and Access Management (IAM) |
IAM allows you to control who has access to your resources. Essential commands include:
Command | Description |
---|---|
gcloud iam service-accounts create SERVICE_ACCOUNT_NAME --display-name "DESCRIPTION" | Creates a new service account |
gcloud projects add-iam-policy-binding PROJECT_ID --member=MEMBER --role=ROLE | Assigns a role to a member |
Example:
gcloud iam service-accounts create my-service-account --display-name "My Service Account"
gcloud projects add-iam-policy-binding my-project --member="serviceAccount:my-service-account@my-project.iam.gserviceaccount.com" --role="roles/editor"
6. Deploying Cloud Functions |
Cloud Functions let you run your code in response to events. Deploy a function using:
gcloud functions deploy FUNCTION_NAME --runtime RUNTIME --trigger-http
Example:
gcloud functions deploy my-function --runtime nodejs14 --trigger-http
7. Managing Cloud SQL Instances |
Cloud SQL provides fully-managed relational databases. Use the following commands to manage instances:
Command | Description |
---|---|
gcloud sql instances list | Lists all Cloud SQL instances |
gcloud sql instances create INSTANCE_NAME --tier=TIER --region=REGION | Creates a new Cloud SQL instance |
gcloud sql instances delete INSTANCE_NAME | Deletes a Cloud SQL instance |
Example:
gcloud sql instances create my-sql-instance --tier=db-f1-micro --region=us-central
8. Monitoring and Logging |
Monitoring and logging are crucial for maintaining system health. Use these commands:
Command | Description |
---|---|
gcloud logging read "LOG_FILTER" | Reads log entries based on a specified filter |
gcloud logging write LOG_NAME "LOG_ENTRY" | Writes a log entry manually (useful for testing or custom logging) |
gcloud monitoring metrics list | Lists available monitoring metrics in your project |
Example:
# Read recent error logs from Compute Engine
gcloud logging read "resource.type=gce_instance AND severity>=ERROR" --limit=10
# Write a test log entry
gcloud logging write my-custom-log "This is a test log entry from CLI"
# List available metrics
gcloud monitoring metrics list
This command helps you quickly pinpoint critical issues by filtering for high-severity logs across VM instances.
9. Automating with Deployment Manager |
Google Cloud Deployment Manager allows you to specify all the resources needed for your application in a declarative format using YAML.
Command | Description |
---|---|
gcloud deployment-manager deployments create DEPLOYMENT_NAME --config=CONFIG_FILE | Creates a new deployment |
gcloud deployment-manager deployments update DEPLOYMENT_NAME --config=CONFIG_FILE | Updates an existing deployment |
gcloud deployment-manager deployments delete DEPLOYMENT_NAME | Deletes a deployment |
Example:
gcloud deployment-manager deployments create my-deployment --config=config.yaml
This is especially useful for replicable infrastructure and DevOps automation pipelines.
10. Exporting Resources to Terraform |
If you’re transitioning from manual gcloud
commands to Infrastructure as Code (IaC) with Terraform, Google Cloud CLI supports exporting your resources:
gcloud beta resource-config bulk-export --resource-format=terraform --path=./tf-export/
This command automatically generates Terraform configurations for existing GCP resources, accelerating your migration to fully managed IaC workflows.
Use Case | Command Example | Notes |
---|---|---|
Set project | gcloud config set project PROJECT_ID | Ensure correct context |
Create VM | gcloud compute instances create my-vm --zone=us-central1-a | Launch new VM |
Upload to Storage | gsutil cp file.txt gs://my-bucket/ | File upload |
Create GKE Cluster | gcloud container clusters create my-cluster --zone=us-central1-a | Spin up Kubernetes cluster |
IAM Role Binding | gcloud projects add-iam-policy-binding ... | Manage permissions |
Deploy Function | gcloud functions deploy my-function --runtime nodejs14 --trigger-http | Serverless deployment |
Create SQL DB | gcloud sql instances create my-sql-instance ... | Managed DB instance |
Read Logs | gcloud logging read "severity>=ERROR" | Troubleshooting |
Deployment Manager | gcloud deployment-manager deployments create ... | Declarative infra |
Export to Terraform | gcloud beta resource-config bulk-export ... | Migrate to Terraform |
Mistake | How to Avoid |
---|---|
Forgetting project context | Always run gcloud config list before operations |
Not using zones or regions | Explicitly specify --zone or --region |
Hardcoding secrets | Use Secret Manager or environment variables |
Ignoring IAM propagation delays | Wait a few seconds after policy changes |
The gcloud
CLI is a vital part of any DevOps toolkit on Google Cloud Platform. By mastering these top 10 commands, DevOps engineers can automate workflows, troubleshoot efficiently, and manage infrastructure at scale. Don’t stop here—explore scripting and integration with other tools like Terraform, GitHub Actions, and Google Cloud Build for a full automation pipeline.
Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.
Learn how to install and configure Google Chrome Remote Desktop on Ubuntu 24.04 with this comprehensive step-by-step guide. Ensure secure and efficient remote access to
Learn how to install Google Cloud CLI on CentOS 9 with this comprehensive guide. Includes step-by-step commands, configuration tips, and troubleshooting advice to help you
Learn how to configure Google Cloud CLI for managing multiple projects on CentOS 9. Step-by-step guide with commands, configuration tips, service account usage, and troubleshooting