© Navin Sabharwal, Shakuntala Gupta Edward 2020
N. Sabharwal, S. G. EdwardHands On Google Cloud SQL and Cloud Spannerhttps://doi.org/10.1007/978-1-4842-5537-7_1

1. Getting Started with GCP

Navin Sabharwal1  and Shakuntala Gupta Edward2
(1)
New Delhi, India
(2)
Ghaziabad, India
 

The cloud computing space is evolving. Every day new offerings from cloud vendors like Google, AWS, and Azure are launched. In the last few years, the offerings have become more mature and stable and are seeing rapid adoption in the enterprise world. Developers are moving from on-premises solutions to adopting the service offerings from cloud providers.

Many of you may be running workloads on the cloud and are aware of the benefits that you are deriving. Let’s reiterate these benefits:
  • Pay per use: This is efficient and cost effective. You pay for the exact amount of resources you consume.

  • Zero maintenance headaches: Operating in the cloud also means no worries about physical hardware infrastructure provisioning, upgrades, or maintenance. The cloud provider takes the responsibility of upgrading and maintaining everything, allowing you to focus on application development.

  • Easy scalability: Providers offer auto-scaling capabilities as your computing needs peek, freeing you from worries about workloads peaks and troughs.

  • Fully accessible: Enables you to work from anywhere at any time and from any device.

  • Quick deployment: Speeds up application development as provisioning with the cloud is just a matter of a few hours, whereas the traditional mode of setting up the infrastructure takes months.

Multiple cloud vendors are competing for the mindshare of the users, and these cloud providers each have their own strengths and capabilities.

The Google Cloud Platform (GCP) is a portfolio of cloud computing services offered by Google. Their services are well positioned for the modern application development user. GCP has some unique offerings in the Big Data analytics, artificial intelligence, and containerization spaces.

Google’s first foray into cloud computing was with Google App Engine, which was launched in April 2008 as a Platform as a Service (PaaS) offering. It enabled developers to build and host apps on Google’s infrastructure. In September 2011, App Engine came out of preview, and in 2013 the Google Cloud Platform name was formally adopted. The company subsequently released a variety of tools, such as its data storage layer, Cloud SQL, BigQuery, Compute Engine, and the rest of the tools that make up today’s Google Cloud Platform.

Figure 1-1 shows that, like any cloud provider, Google offers core IaaS (infrastructure as a Service) services for the compute, storage, networking, security, and databases spaces.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig1_HTML.jpg
Figure 1-1

Cloud providers’ core services

Apart from the core services, Google offers PaaS (Platform as a Service) services as well, such as Pub/Sub, DataFlow, AI Hub, and machine learning, to name a few. These PaaS services are built on top of the core stack of services. Google is constantly innovating to strengthen its base further and continues to add to these PaaS services.

This book focuses on the database service offerings in the relational space. Cloud databases are indisputably the future of enterprise databases. Database as a Service (DBaaS) solves the challenges inherent to the traditional on-premises model.

Google is one vendor that is leveraging its strengths in data processing and is establishing its dominance in the Big Data segment. Google’s DBaaS services were born out of their internal database management models. It brings in differentiated products to this category. In addition, as compared to the other vendors, Google DBaaS users get to achieve high levels of customization, which are covered in the coming chapters.

Despite being a late entrant in the cloud domain, Google has quickly risen to deliver the best performance for the price in the DBaaS segment.

Before you start using any of the GCP services, you need to know how to get started with GCP. Let’s begin exploring the platform. This chapter walks through the Google Cloud Platform.

Signing Up

It’s time to get started with GCP. The first step is to sign up for GCP. The following steps are required for signing up and are more relevant to first time users.

The primary prerequisite for signing up is a Google account. GCP uses Google accounts for access management and authentication. As shown in Figure 1-2, you enter the https://console.cloud.google.com URL in your browser window and click the Try For Free button.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig2_HTML.jpg
Figure 1-2

Google Cloud Platform

You will be redirected to the Sign In page, as shown in Figure 1-3.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig3_HTML.jpg
Figure 1-3

GCP sign in

This prompts you for a Google account. If you don’t have a Google account, follow the Create Account process to create one. If you are eligible for the free tier, you will be prompted for the account details, as shown in Figure 1-4.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig4_HTML.jpg
Figure 1-4

GCP free tier registration, step 1

Select your country, agree to the terms of service, and click the Agree and Continue button. This will take you to the second step, as shown in Figure 1-5, wherein you create and select your payment profile. Provide the required billing details; however, rest assured that the auto debit will not happen unless you manually choose that option.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig5_HTML.jpg
Figure 1-5

GCP free tier registration, step 2

While you create your payment profile and sign in, the right panel displays details, as shown in Figure 1-6.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig6_HTML.jpg
Figure 1-6

GCP free tier information

As you can see, Google gives a free trial of $300 to everyone to be spent over a period of 12 months. This is sufficient not only to explore all the exercises in this book but also to evaluate GCP further.

Once you have specified all the details, click on the Start My Free Trial button.

It will take a while for the registration to be completed. Once the necessary validations are done, you will be redirected to the Google Console and are ready to get started.

Note

If you are already signed into an account, you will be directly sent to the GCP Cloud Console.

Accessing Google Cloud Platform

Now that you have signed up, you can next look at accessing the GCP services and resources using a web-based graphical user interface (a Cloud Console) and a command line (a Cloud Shell).

Cloud Console

Navigate to https://console.cloud.google.com. If you’re not already signed in, it will prompt you to enter the Google account credentials. Once you’re signed in, it will redirect you to the Cloud Console, as shown in Figure 1-7.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig7_HTML.jpg
Figure 1-7

GCP Cloud Console

In the top-most panel, next to the GCP icon, a dropdown appears with My First Project selected. This is the project dropdown, and My First Project is a new project that’s automatically created when you first sign in.

A project can be thought of as a container for your work, wherein all the resources are isolated from the resources created in other projects. You will learn about projects and how you create a project in a while.

The center of the console is a dashboard that gives you a bird’s eye view of the selected project. The view is further divided into multiple cards wherein each card refers to specific information.

The Project Info card shown in Figure 1-8 gives details about the project, such as the names and IDs, along with a quick link at the bottom enabling easy modification of the project settings.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig8_HTML.jpg
Figure 1-8

Project Info card

The Google Cloud Platform status card, as shown in Figure 1-9, gives you a quick status check. Green indicates that everything is working fine.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig9_HTML.jpg
Figure 1-9

GCP status card

The billing card shows the billing details at a glance for the selected project, as shown in Figure 1-10.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig10_HTML.jpg
Figure 1-10

Billing card

There is also a card for Quick Starts, as shown in Figure 1-11, which you could use when exploring GCP services and offerings.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig11_HTML.jpg
Figure 1-11

Quick Start card

On the left side of the top-most panel is the navigation button, as shown in Figure 1-12. Clicking this button opens the navigation menu where all the GCP offerings are categorized and listed.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig12_HTML.jpg
Figure 1-12

Left navigation menu of the Cloud Console

You will come back and explore the menu when subsequent chapters cover the relevant areas. Feel free to familiarize yourself by exploring this console.

Cloud Shell

Now that you have familiarized yourself with the web console, next you learn how to manage the resources using commands and scripts.

The GCP Cloud Shell option enables you to access and manage its resources directly from the command line. Click on the Activate Cloud Shell button in the top-right corner of the Cloud Console, as shown in Figure 1-13, to access the Cloud Shell.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig13_HTML.jpg
Figure 1-13

Activating the Cloud Shell

This opens the pop up shown in Figure 1-14.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig14_HTML.jpg
Figure 1-14

Google Cloud Shell

Click on Start Cloud Shell to get started. The Cloud Shell session opens inside a new frame at the bottom of the console, as shown in Figure 1-15.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig15_HTML.jpg
Figure 1-15

Connecting a Cloud Shell session

It takes a few seconds to initialize the Cloud Shell session as Google spins up an active instance for this. This instance runs on the Google Cloud and provides a complete environment to connect to the various resources in the cloud.

The Cloud Shell instances are provisioned on a per user and per session basis. The instances persist while the session is active and are terminated after an hour of inactivity.

After the initialization, a command prompt is displayed for you, as shown in Figure 1-16. You can start keying in your commands.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig16_HTML.jpg
Figure 1-16

Cloud Shell command prompt

You can start multiple sessions to the same instance by clicking on the + icon, as shown in Figure 1-17.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig17_HTML.jpg
Figure 1-17

Multiple Cloud Shell session

This opens a new tab to the same instance, as shown in Figure 1-18.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig18_HTML.jpg
Figure 1-18

Cloud Shell new session of the same instance

The Cloud Shell automatically authenticates the logged-in account ID and picks the active/selected project as the current default. This can be seen on the command prompt. Figure 1-19 shows that the project ID is displayed on the command prompt.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig19_HTML.jpg
Figure 1-19

Active project as default

With Cloud Shell, the Cloud SDK gcloud command and other utilities are available. They enable you to work with the resources and perform a whole bunch of operations. There’s no need to install or set up anything.

Let’s start keying in a few commands using gcloud. You will start by validating the current default project set (see Listing 1-1). Enter the gcloud config list project command.
Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to igneous-future-248210.
Use "gcloud config set project [PROJECT_ID]" to change to a different project.
architectbigdata@cloudshell:~ (igneous-future-248210)$ gcloud config list project
[core]
project = igneous-future-248210
Your active configuration is: [cloudshell-30918]
architectbigdata@cloudshell:~ (igneous-future-248210)$
Listing 1-1

Validate Default Project Set

This displays the selected project. Next, you validate which active account is authenticated to work with the selected project by using the gcloud auth list command (see Listing 1-2).
architectbigdata@cloudshell:~ (igneous-future-248210)$ gcloud auth list
      Credentialed Accounts
ACTIVE  ACCOUNT
*       [email protected]
To set the active account, run:
    $ gcloud config set account `ACCOUNT`
architectbigdata@cloudshell:~ (igneous-future-248210)$
Listing 1-2

Validate the Active Account

You can see that the logged-in account is being set as the active account. The Cloud Shell is a full-fledged command line on the browser, so you can run Linux commands.

You can change the active account as well as the current default project set using gcloud commands. Type gcloud –h to get help on what commands are available with gcloud (see Listing 1-3).
architectbigdata@cloudshell:~ (igneous-future-248210)$ gcloud -h
Usage: gcloud [optional flags] <group | command>
  group may be           access-context-manager | ai-platform | alpha | app |
                         asset | auth | beta | bigtable | builds | components |
                         composer | compute | config | container | dataflow |
                         dataproc | datastore | debug | deployment-manager |
                         dns | domains | endpoints | filestore | firebase |
                         functions | iam | iot | kms | logging | ml |
                         ml-engine | organizations | projects | pubsub | redis |
                         resource-manager | scheduler | services | source |
                         spanner | sql | tasks | topic
  command may be         docker | feedback | help | info | init | version
For detailed information on this command and its flags, run:
  gcloud --help
architectbigdata@cloudshell:~ (igneous-future-248210)$
Listing 1-3

Get Help on Commands

You can see a list of all the commands. Using gcloud <<command>> --help or gcloud help <<command>>, you can check the usage of a specific command.

From the commands listed, determine what the config command is used for. Use the gcloud config help command (see Listing 1-4).
architectbigdata@cloudshell:~ (igneous-future-248210)$ gcloud help config
Listing 1-4

Help on Config Command

It displays complete information about the command, as shown in Listing 1-5.
NAME
    gcloud config - view and edit Cloud SDK properties
SYNOPSIS
    gcloud config GROUP | COMMAND [GCLOUD_WIDE_FLAG ...]
DESCRIPTION
    The gcloud config command group lets you set, view and unset properties
    used by Cloud SDK.
    A configuration is a set of properties that govern the behavior of gcloud
    and other Cloud SDK tools. The initial default configuration is set when
    gcloud init is run. You can create additional named configurations using
    gcloud init or gcloud config configurations create.
    To display the path of the active configuration along with information
    about the current gcloud environment, run $ gcloud info.
    To switch between configurations, use gcloud config configurations
    activate.
    gcloud supports several flags that have the same effect as properties in a
    configuration (for example, gcloud supports both the --project flag and
    project property). Properties differ from flags in that flags affect
    command behavior on a per-invocation basis. Properties allow you to
    maintain the same settings across command executions.
    For more information on configurations, see gcloud topic configurations.
GCLOUD WIDE FLAGS
    These flags are available to all commands: --account, --billing-project,
    --configuration, --flags-file, --flatten, --format, --help,
    --impersonate-service-account, --log-http, --project, --quiet,
    --trace-token, --user-output-enabled, --verbosity. Run $ gcloud help for
    details.
GROUPS
    GROUP is one of the following:
     configurations
:
Listing 1-5

Config Help Output

Note

Press Enter to navigate through the output. Once you’re done, press q to return back to the shell.

Now that you know that the config command helps you manage properties, you can use gcloud config list to view which properties are set in the configuration for this instance. See Listing 1-6.
architectbigdata@cloudshell:~ (igneous-future-248210)$ gcloud config list
[component_manager]
disable_update_check = True
[compute]
gce_metadata_read_timeout_sec = 5
[core]
disable_usage_reporting = False
project = igneous-future-248210
[metrics]
environment = devshell
Your active configuration is: [cloudshell-30918]
architectbigdata@cloudshell:~ (igneous-future-248210)$
Listing 1-6

View Properties Set in the Configuration

It displays only the properties that have changed and are different from the default settings. For example, you can see the account is set to the Gmail ID and the project is set to the selected project. You can use gcloud config list –all to view all the properties that can be managed using this command.

It lists all the properties with a few marked as unset. These are the ones that are either default or are not yet set. See Listing 1-7.
architectbigdata@cloudshell:~ (igneous-future-248210)$ gcloud config list --all
enabled (unset)
[healthcare]
dataset (unset)
location (unset)
[interactive]
bottom_bindings_line (unset)
bottom_status_line (unset)
completion_menu_lines (unset)
context (unset)
fixed_prompt_position (unset)
help_lines (unset)
hidden (unset)
justify_bottom_lines (unset)
manpage_generator (unset)
multi_column_completion_menu (unset)
prompt (unset)
show_help (unset)
suggest (unset)
[metrics]
environment = devshell
[ml_engine]
local_python (unset)
polling_interval (unset)
[proxy]
address (unset)
password (unset)
port (unset)
rdns (unset)
type (unset)
username (unset)
[redis]
region (unset)
[scc]
organization (unset)
[spanner]
instance (unset)
[survey]
disable_prompts (unset)
Your active configuration is: [cloudshell-30918]
architectbigdata@cloudshell:~ (igneous-future-248210)$
Listing 1-7

View All Properties of the Configuration

You saw how easy it is to work with the Cloud Shell. It’s an easy way to get up and running with the Google Cloud. The book uses the Console as it walks through the topics. Feel free to explore the other commands.

gcloud, the powerful and unified command-line tool for the Google Cloud Platform, is especially useful when you want to script operations that need to be performed on a regular, routine basis. Rather than running the steps manually, you can run the script and free up the manual resources from mundane tasks.

Cloud SDK

The Cloud Shell option is typically used when you can’t download the software on your local machine. However, since the VM instances are spun up temporarily, it’s not a very good option when you have to do development intensively using Google Cloud.

In that case, downloading and using Google Cloud SDK is the better option. Google provides command-line tools and APIs to interact with its services and resources via Google Cloud SDK.

The book will return to its usage when you start working with the services offered by GCP in the coming chapters. Before you go any further, it’s important to briefly understand what a project is and how you create a new one.

Project

When you first signed up for GCP, you learned that GCP automatically creates a new project named My First Project, which is basically used to isolate the resources of the project from the resources of other projects.

A project is the base organizing entity; primarily a container for all the resources you create. It’s a must to get started with GCP. For example, if you create a new instance, it will be owned by a project. Further, any charges incurred by the resources will be charged to its project.

Ownership: Projects and Billing

The project is the top-level billing instance, which implies that billing in GCP happens at the project level and not at the account level.

The billing account that you created at the start is by default associated with the project; however, different billing accounts can be specified for each project you create. That way, if you have a bunch of Google Cloud projects going on in the same organization, you can ask different departments or different teams within a department to pay for it.

So, you can have multiple projects associated with a single billing account or you can have multiple billing accounts, each associated with different projects. You use the billing menu to manage project-wise billing accounts. Figure 1-20 displays the default billing account overview and the projects linked to the account.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig20_HTML.jpg
Figure 1-20

Billing account overview

Figure 1-21 shows the context menu associated with the accounts. Clicking on the context menu enables you to disable the billing account for the project or change the billing account. If no action is taken, the projects billing continues to happen through this account only.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig21_HTML.jpg
Figure 1-21

Billing account context menu

The billing of a project happens based on the services used within.

Projects and Isolations

Not only does the project own a resource, but it is also used to isolate the resources from one another. This means that if users have access to view a project, they will have access to all its resources but will not be able to view resources in other projects unless specified. This is very useful in controlling who views what.

Project as Namespace

A project also serves as a namespace, which means every resource in a project must have a unique name. As an example, consider the actual environment depicted in Figure 1-22.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig22_HTML.jpg
Figure 1-22

Actual environment

There are various departments and development teams. Teams work on various products. Each product has a Dev environment, a Test environment, and a Production environment.

In GCP, each environment should be represented as a project, which is an organizing unit of all resources required to achieve a precise objective. So in GCP, the environment from Figure 1-22 will look like Figure 1-23.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig23_HTML.jpg
Figure 1-23

GCP project organization of the actual environment

You need to create multiple projects, each pertaining to a specific need or requirement.

In addition, say you have customer-specific implementations. You can then have customer specific projects, wherein resources and changes within a project are visible only to that customer’s users and not to others.

Create a Project

Now that you’re familiar with what a project is, it’s time to create a project. Click on the Projects dropdown appearing in the top-most panel, as shown in Figure 1-24.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig24_HTML.jpg
Figure 1-24

Projects dropdown

Figure 1-25 shows the pop up that will appear with all projects listed under Recent. In this case, the default created project is visible.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig25_HTML.jpg
Figure 1-25

Recent project list

Click on New Project. A window will appear, as shown in Figure 1-26.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig26_HTML.jpg
Figure 1-26

Create a new project

Note

If you are using the trial quota, you’ll have a limit of 23 projects. This is sufficient for the examples in the book.

All projects consist of the following:
  • Project Name: A display name that’s mutable and is provided while creating.

  • Project ID: This comes prepopulated but you can change it. The ID is unique across GCP. Once the project is created, it cannot be changed. The ID cannot be used again, even if you delete the project.

  • Project Number: Provided by GCP. It is automatically assigned when the project is created and is read-only.

To follow along with the example here, try creating a project named ExampleGettingStarted . Figure 1-27 shows the pop up with the name specified.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig27_HTML.jpg
Figure 1-27

Project ExampleGettingStarted

Click on Create to create the project. Once you have created the project, it will start appearing in the project dropdown, as shown in Figure 1-28. Click on the dropdown and select the project.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig28_HTML.jpg
Figure 1-28

Project created and displayed in the project list

You will be redirected to the Cloud Console with the selected project set as active, as shown in Figure 1-29.
../images/489070_1_En_1_Chapter/489070_1_En_1_Fig29_HTML.jpg
Figure 1-29

Newly created project’s Cloud Console

In order to interact with most GCP resources, you must provide the identifying project information for every request. This is either a project ID or a project number.

Summary

This chapter covered the basics of getting started with GCP. The next chapter will start with Cloud SQL.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.94.153