Cloud Security

Getting Started with Google Cloud Platform

Cloud Security
Feb 21, 2023
6 mins
Saumya Kasthuri

Google Cloud Platform is a cloud-based computing platform that offers a variety of services for businesses and individuals, including computing, storage, and big data analytics.

In this blog, I will be diving into the process of creating a Google Cloud Platform (GCP) account and getting familiar with the gcloud command-line interface (CLI).

Table of Contents

  1. Setting up a GCP account
  2. Command line Tools : gcloud & gsutil
  3. gsutil for Google Cloud Storage
  4. gcloud — multi-purpose command-line tool
  5. Configuring the gcloud CLI
  6. Common gcloud CLI Commands
  7. Common gsutil Commands

Setting up a GCP account

  1. Open Google Cloud console in a browser.
  2. When prompted to sign in, create a new account by clicking Create account:
  3. Follow the instructions to register your corporate email address as a Google account. Alternatively, you can use a Gmail account or other Google account.
  4. Continue to the Google Cloud console and accept the Google Cloud Platform terms presented.
  5. Open the Google Cloud console and log in with the account you created in step 1.
  6. Click the Project Selector at the top of the view. The Project Selector dialog box displays:

7. Click New Project in the upper right. The New Project view displays.

8. Enter a friendly name for your project in the Project name field.

9. Google Cloud Platform generates a corresponding project ID below the Project name field, as the following example shows:

Create New Project

10. You can change the generated project ID by clicking Edit, but the project ID must be unique.

11. Take note of the project ID. You will use it later in this setup process. NOTE: After you create the project, you cannot change the project ID.

12. In the Billing account field, select the account that you will use to pay for your project.

13. In the Location field, select a folder for your project. Folders are an optional part of the Google Cloud Platform project resource tree. Click Create.

14. Google Cloud Platform creates your new project.

Project Dashboard

Command line Tools : gcloud & gsutil

Google Cloud services offer a wide range of tools and services for managing data and computing resources. Two popular command-line tools for interacting with these services are gsutil and gcloud. While they may seem similar, these two tools serve different purposes.
Let’s take a closer look at the key differences between gsutil and gcloud.

gsutil

  • gsutil is a command-line tool specifically for interacting with Google Cloud Storage (GCS).
  • GCS is a highly scalable, highly available, and durable object storage service provided by Google.
  • gsutil provides a set of commands for managing data in GCS, including uploading and downloading files, managing buckets and objects, and performing other tasks related to data management in GCS.

gcloud

  • gcloud is a multi-purpose command-line tool for interacting with multiple Google Cloud services, including GCS, Google Compute Engine, Google App Engine, and others.
  • In addition to providing a set of commands for interacting with GCS, gcloud provides a unified interface for interacting with multiple Google Cloud services.
  • This means you can use gcloud to manage resources across different Google Cloud services using a consistent set of commands.

Which One to Use?

Deciding between gsutil and gcloud depends on your specific needs. If you only need to manage data in GCS, then gsutil is the way to go. It provides a more focused set of commands specifically for GCS. On the other hand, if you need to manage resources across multiple Google Cloud services, then gcloud is the better choice. It provides a more comprehensive set of commands and a consistent interface across multiple services.

How to get started:

  1. Download the Google Cloud CLI installer.
  2. Install gcloud cli (gcloud,gsutil,bq are included)
  3. Initialize the gcloud CLI:
    gcloud init
    If you are in a remote terminal session, you can use the — console-only flag to prevent the command
    from launching a browser-based authorization flow, if required:
    gcloud init--console-only
  4. Create or select a configuration if prompted.
  5. Complete the authorization step when prompted.
    gcloud auth login
  6. Choose a current Google Cloud project if prompted or create a new project.
    gcloud config set project <project-id>

Common gcloud CLI Commands

Now that you’ve installed the Google Cloud SDK and authenticated your account, let’s look at some of the most commonly used gcloud CLI commands.

gcloud auth login: Create account in google cloud. Returns a URL. Access & login

gcloud auth list : Once you logged into the gcloud account. The auth token will be stored in the system.

gcloud config set project <project-id> : To configure a project gcloud config get project

gcloud compute instances list: This command lists all of the virtual machine instances in your project.

gcloud compute instances create <instance-name>: This command creates a new virtual machine instance with the specified name.

gcloud compute ssh <instance-name>: This command opens an SSH connection to a virtual machine instance.

gcloud compute firewall-rules create <firewall-rule-name>: This command creates a new firewall rule in your project.

gcloud compute disk create <disk-name>: This command creates a new disk in your project.

gcloud compute images list: This command lists all of the images in your project.

gcloud compute snapshots list: This command lists all of the snapshots in your project.

Common gsutil Commands

Uploading Files to GCS

One of the most common tasks you’ll perform with gsutil is uploading files to GCS. To upload a file to GCS, simply run the following command:

gsutil cp <file-path> gs://<bucket-name>/<object-name>

Where <file-path> is the path to the file you want to upload, <bucket-name> is the name of the bucket you want to upload the file to, and <object-name> is the name you want to give the file in GCS.

For example, to upload a file named file.txt to a bucket named my-bucket with the object name file.txt, you would run the following command:

gsutil cp file.txt gs://my-bucket/file.txt

Downloading Files from GCS

In addition to uploading files, you can also download files from GCS with gsutil. To download a file from GCS, simply run the following command:

gsutil cp gs://<bucket-name>/<object-name> <file-path>

Where <bucket-name> is the name of the bucket the file is stored in, <object-name> is the name of the file in GCS, and <file-path> is the path where you want to save the file.

For example, to download a file named file.txt from a bucket named my-bucket, you would run the following command:

gsutil cp gs://my-bucket/file.txt file.txt

Managing Buckets and Objects

In addition to uploading and downloading files, gsutil provides several commands for managing buckets and objects in GCS.

  1. gsutil mb gs://<bucket-name>: This command creates a new bucket with the specified name.
  2. gsutil rb gs://<bucket-name>: This command deletes a bucket with the specified name.
  3. gsutil ls gs://<bucket-name>: This command lists the objects in a bucket.
  4. gsutil rm gs://<bucket-name>: This command removes objects and/or buckets

The gcloud CLI and gsutil are powerful tool that makes it easy to interact with GCP services from the command line. gsutil is a specialized tool for interacting with Google Cloud Storage, while gcloud is a general-purpose tool for interacting with multiple Google Cloud services. If you're only working with GCS, gsutil is likely the better choice. But if you're working with multiple Google Cloud services, gcloud may be a more convenient choice.

HAZE WEBFLOW TEMPLATE

Build a website that actually performs better.

1
Lorem ipsum dolor sit amet consectutar
2
Lorem ipsum dolor sit amet consectutar
3
Lorem ipsum dolor sit amet consectutar