Starting an instance

Exclusive offer: get 50% off this eBook here
Instant Google Compute Engine [Instant]

Instant Google Compute Engine [Instant] — Save 50%

A quick guide to managing and operating your personal Cloud infrastructure using Google Compute Engine with this book and ebook

$14.99    $7.50
by Alexander Papaspyrou | October 2013 | Open Source

This article by Alexander Papaspyrou, the author of Instant Google Compute Engine provides you with all the information you need to run your large-scale computing workloads on Linux virtual machines hosted on Google's infrastructure. You will also get to know the basic building blocks of Google Compute Engine (GCE), get started with creating and running your infrastructure in the Cloud, and learn about the different concepts that make up a well-performing GCE system.

(For more resources related to this topic, see here.)

When you add a new instance to your project, it is automatically started. After a few moments, it will be ready for logging in using SSH. In order to create and start an instance, run the following command:

% gcutil –-project=<project_id> addinstance <instance_name>

gcutil will interactively collect the necessary details on the command line.

For our example, we create a new instance called hello-google-compute:

% gcutil –project=packt-gce-starter addinstance hello-gce INFO: Waiting for insert of instance hello-gce. Sleeping for 3s. [omitted]

The omitted output will show information on the zone, image, and machine type selected during interactive setup and provide a return code to indicate whether the operation was successful.

If you wish to create an instance non-interactively, you will have to set a few additional parameters. The instance name must only contain lower-case letters, numbers, or dashes and it must start with a letter.

Option

Description

--machine-type

The machine type to host the instance. gcutillistmachinetypes displays a list of available machine types, and gcutil getmachinetype provides details on a specific machine type.

--image

The name of the image to install, from the project's images collection. gcutil listimages displays a list of available images, and gcutil getimage provides details on a specific image.

A comprehensive list of options can be listed by running the following command:

% gcutil help addinstance

After creation, your instance will be also displayed in the Google Cloud Console.

% gcutil --project=<project_id> listinstances

By default, every instance has a network setup that allows the virtual machine to communicate with other machines in the same network and with the rest of the world via the Internet. Note that, however, communication is restricted by the default firewall to incoming SSH traffic; see The Firewall object section for details.

Information on a newly created instance

Information on a newly created instance

 

Checking the status of an instance

After having started an instance, or for routine checks during the management of your GCE infrastructure, you may want to check the status of a given virtual machine. This can be done either via the Web UI, as shown in the preceding screenshot, or by calling:

% gcutil --project=<project_id> getinstance <instance_name>

For our test instance, this will yield something like:

% gcutil –-project=packt-gce-starter getinstance hello-gce +------------------------+-------------------------------------+ | property | value | +------------------------+-------------------------------------+ | name | hello-gce | | description | | | creation-time | 2013-05-27T11:02:54.825-07:00 | | machine | machineTypes/n1-standard-1 | | | | | status | RUNNING | | status-message | | | | | | disk | 0 | | type | EPHEMERAL | | mode | READ_WRITE | | | | | network-interface | | | network | networks/default | | ip | 10.240.17.7 | | access-configuration | External NAT | | type | ONE_TO_ONE_NAT | | external-ip | 192.158.30.140 | +------------------------+-------------------------------------+

Note the status line within the above output; it says RUNNING. This indicates that the machine is ready to be used.

GCE instance states and transitions

 

Every instance in GCE has a defined status lifecycle, as shown in the preceding figure, and the following states are known:

Status

Description

PROVISIONING

Resources are being reserved for the instance, but the virtual machine is not running yet.

STAGING

Resources have been acquired for the instance, and the virtual machine is prepared for launch.

RUNNING

The instance is booting up or running.

STOPPED

The instance has been either shutdown, or it failed. Subsequently, it will either reboot (changing to PROVISIONING), or stop (changing to TERMINATED).

TERMINATED

The instance has been either shutdown or it failed, and rebooting the virtual machine is not an option. This status is permanent, and the instance must be deleted and recreated.

Logging in to your instance

As mentioned before, the default network setup allows you to connect to your instance via the SSH protocol. GCE automatically handles key management for you and your project members. To relieve you from the hassle of key handling, gcutil wraps SSH and takes care of sorting out password-less authentication correctly.

To login to your instance via SSH, run the following command from your workstation computer:

% gcutil --project=<project_id> ssh <instance_name>

For our example, you would do the following:

% gcutil --project=packt-gce-starter ssh hello-gce INFO: Zone for 'hello-gce' detected as u'europe-west1-a'. INFO: Running command line: ssh -o UserKnownHostsFile=/dev/null -o
CheckHostIP=no -o StrictHostKeyChecking=no -i /Users/packt
/.ssh/google_compute_engine -A -p 22 packt@192.158.30.140 --
[omitted] packt@hello-gce:~$

As mentioned before, GCE takes care of SSH through the gcutil. In fact, gcutil does a lot! Most importantly, it checks whether you already have a public/private key pair and, if not, creates one for you. It also takes care of uploading your public key to the Google Cloud Console and associating it with your Google user account. In addition, it automatically injects your public key into every instance so that you can directly login, even if you did not set up a user account within the OS image.

If you wish to use a different SSH client, you will have to manage usage and the upload of the correct key manually. gcutil stores the generated key pair in your home folder under the hidden directory ~/.ssh. There, you will (besides others) find two files:

  • google_compute_engine (your private key)
  • google_compute_engine.pub (your public key)

Even if you do not wish to use gcutil for SSH'ing into your virtual machines, you should go through its setup routine at least once so that your keys are generated and uploaded to the Google Cloud Console; otherwise, you will not be able to login.

One ring to rule them all

During initial key ring generation, gcutil will ask you to enter and repeat a passphrase to protect your SSH key. Although you can leave the passphrase empty, we strongly recommend not doing so. If you do not protect your key with a passphrase, anyone who gets hold of your workstation computer can easily copy your key and will then have full administrative access to your whole GCE infrastructure!

Summary

Thus we learned how to get started with creating and running your infrastructure in the Cloud and few concepts that make up a well-performing GCE system.

Resources for Article :


Further resources on this subject:


Instant Google Compute Engine [Instant] A quick guide to managing and operating your personal Cloud infrastructure using Google Compute Engine with this book and ebook
Published: September 2013
eBook Price: $14.99
See more
Select your format and quantity:

About the Author :


Alexander Papaspyrou

Alexander Papaspyrou has over 15 years of experience in IT. He is a Computer Scientist at heart, with a strong focus on distributed computing and Cloud Infrastructure. He has worked on many e-Infrastructure projects in varying domains, from climate prediction to manufacturing. With rockstarengineering.com, he provides consultancy on IT infrastructure efforts and the stress field between technological, regulatory, and standardisation challenges.

He was previously employed as a researcher, and helped to create the Open Cloud Computing Interface family of specifications, which emerged from the lack of a royalty-free, open interface to a modern as-a-service environment, and now gains momentum with implementations in major Cloud middleware stacks such as OpenNebula and OpenStack, and uptake in platform frameworks such as CompatibleOne.

He is a regular speaker at conferences in the distributed computing domain and he has authored over 30 books and articles.

Books From Packt


Google Web Toolkit 2 Application Development Cookbook
Google Web Toolkit 2 Application Development Cookbook

Getting Started with Google Guava
Getting Started with Google Guava

Google Plus First Look: a tip-packed, comprehensive look at Google+
Google Plus First Look: a tip-packed, comprehensive look at Google+

Google Visualization API Essentials
Google Visualization API Essentials

Google Apps: Mastering Integration and Customization
Google Apps: Mastering Integration and Customization

Google App Inventor
Google App Inventor

Instant Google Drive Starter
Instant Google Drive Starter

Learning Google Guice
Learning Google Guice


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software