Deploying to Google Compute Engine

Hands-On Lab

 

Photo of Joseph Lowery

Joseph Lowery

Google Cloud Training Architect II in Content

Length

00:30:00

Difficulty

Beginner

To take advantage of Google Cloud’s Compute Engine power and flexibility, you’ll need to not only understand how to create instances, but also how to deploy applications onto those instances. It’s not uncommon to create separate instances for the front-end and the back-end aspects of the application. One method of deploying an application on Compute Engine instances is to connect to the instance via SSH and install the required code. In this lab, you’ll use this technique to install a MongoDB database on the back-end instance and a ToDo application, written in Node.js, on the front-end one. Once the app is up and running, you’ll verify it is working by checking the external IP of the front-end instance.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Deploying to Google Compute Engine

In this lab, we'll install a MongoDB database on the backend instance and a ToDo application, written in Node.js, on the frontend one. Once the app is up and running, we’ll verify it is working by checking the external IP of the frontend instance.

How to Log in to Google Lab Accounts

On the lab page, right-click Open GCP Console and select the option to open it in a new private browser window (this option will read differently depending on your browser — e.g., in Chrome, it says "Open Link in Incognito Window"). Then, sign in to Google Cloud Platform using the credentials provided on the lab page.

On the Welcome to your new account screen, review the text, and click Accept. In the "Welcome L.A.!" pop-up once you're signed in, check to agree to the terms of service, choose your country of residence, and click Agree and Continue.

You're now logged in to the Google Cloud Platform console.

Deploying to Google Compute Engine

Now, on to the lab!

Create backend instance.

  1. Navigate to Compute Engine > VM instances.
  2. Click Create.
  3. Name the instance "la-backend-1"
  4. Change the region to us-central1.
  5. Choose the f1-micro machine type.
  6. Change the boot disk to Ubuntu 14.04 LTS.
  7. For the firewall, select to Allow HTTP access.
  8. Click Create.

Create frontend instance.

  1. In the top navigation, click the plus-sign icon to create a new instance.
  2. Name the instance "la-frontend-1".
  3. Change the region to us-central1.
  4. Choose the f1-micro machine type.
  5. Change the boot disk to Ubuntu 14.04 LTS.
  6. For the firewall, select to Allow HTTP access.
  7. Click Create.

Connect to backend instance via SSH.

  1. Click the SSH button associated with the la-backend-1 instance.

Set up MongoDB database.

  1. Update the packages:

    sudo apt-get update
  2. Install MongoDB:

    sudo apt-get install mongodb
  3. Stop the database:

    sudo service mongodb stop
  4. Make the directory for the database:

    sudo mkdir $HOME/db
  5. Run MongoDB in the background on port 80, and set the log path:

    sudo mongod --dbpath $HOME/db --port 80 --fork --logpath /var/tmp/mongodb
  6. Exit SSH:

    exit

Connect to frontend instance via SSH.

  1. Click the SSH button associated with the la-frontend-1 instance.

Install and run files for front end.

  1. Update the packages:

    sudo apt-get update
  2. Install Git and Node.js:

    curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash –
    sudo apt-get install git nodejs
  3. Clone the sample app:

    git clone https://github.com/GoogleCloudPlatform/todomvc-mongodb.git
  4. Install npm:

    cd todomvc-mongodb; npm install
  5. Change the configuration in the server.js file to work with port 80:

    sed -i -e 's/8080/80/g' server.js
  6. Start the app using the instances' internal IP addresses, which you can grab from the VM instances page in the GCP console:

    sudo nohup nodejs server.js --be_ip <backend-internal-ip> --fe_ip <front end-internal-ip>
  7. Exit SSH:

    exit

Test application.

  1. From the VM instances page, click the External IP address link for the la-frontend-1 instance.
  2. Test the ToDo application.

Conclusion

Congratulations on completing this lab!