Getting Started with Google Cloud Platform: A Beginner’s Guide to Cloud Excellence

6.23K 0 0 0 0

📘 Chapter 3: Deploying Your First Application on GCP

🔍 Overview

After setting up your GCP account and understanding core services, it’s time to deploy your first real-world application. Google Cloud makes it easy to host applications using a variety of compute options—whether it's a static site, a containerized service, or a dynamic backend API.

This chapter walks you through:

  • Deploying a static website with Cloud Storage
  • Running a dynamic app on App Engine
  • Serving containers with Cloud Run
  • Managing VM-based apps via Compute Engine
  • Connecting to databases like Cloud SQL
  • Enabling logging and monitoring

🧱 1. Prerequisites

Before deploying:

  • Set up a billing account
  • Enable the necessary APIs:

bash

 

gcloud services enable compute.googleapis.com \

                        appengine.googleapis.com \

                        run.googleapis.com \

                        sqladmin.googleapis.com \

                        cloudbuild.googleapis.com

  • Install the Google Cloud CLI (gcloud) or use Cloud Shell

🖼️ 2. Deploying a Static Website on Cloud Storage

Step-by-Step:

  1. Create a Bucket

bash

 

gsutil mb -l US gs://your-bucket-name

  1. Make the Bucket Public

bash

 

gsutil iam ch allUsers:objectViewer gs://your-bucket-name

  1. Enable Static Website Hosting

bash

 

gsutil web set -m index.html gs://your-bucket-name

  1. Upload Files

bash

 

gsutil cp index.html gs://your-bucket-name

  1. Visit the Public URL
    http://storage.googleapis.com/your-bucket-name/index.html

Feature

Value

Storage Class

Standard

Access Control

Uniform (recommended)

Cost

Free Tier: 5 GB/month


🚀 3. Deploying a Dynamic Web App with App Engine

Use Case: Python Flask App

1. Create App Engine Project

bash

 

gcloud app create --region=us-central

2. Sample main.py

python

 

from flask import Flask

app = Flask(__name__)

 

@app.route('/')

def hello():

    return 'Hello from App Engine!'

3. app.yaml

yaml

 

runtime: python310

entrypoint: gunicorn -b :$PORT main:app

 

handlers:

- url: /.*

  script: auto

4. Deploy

bash

 

gcloud app deploy

5. Visit URL:
https://<your-project-id>.appspot.com


️ 4. Deploying a Containerized App with Cloud Run

Use Case: Dockerized Node.js App

1. Dockerfile

dockerfile

 

FROM node:18

WORKDIR /app

COPY . .

RUN npm install

CMD ["node", "server.js"]

2. Build Image

bash

 

gcloud builds submit --tag gcr.io/your-project-id/hellorun

3. Deploy to Cloud Run

bash

 

gcloud run deploy hellorun \

  --image gcr.io/your-project-id/hellorun \

  --platform managed \

  --region us-central1 \

  --allow-unauthenticated

Feature

Benefit

Stateless Containers

Automatically scale to zero

Bill Per Request

Cost-effective for infrequent usage

HTTP URL Provided

Auto HTTPS, custom domains supported


💻 5. Hosting on Compute Engine (VM)

1. Launch a VM

bash

 

gcloud compute instances create web-vm \

  --zone=us-central1-a \

  --machine-type=e2-micro \

  --image-family=debian-11 \

  --image-project=debian-cloud \

  --tags=http-server

2. Install Web Server

bash

 

sudo apt update

sudo apt install apache2 -y

3. Make Web Page

bash

 

echo "Hello GCP VM!" | sudo tee /var/www/html/index.html

4. Add Firewall Rule

bash

 

gcloud compute firewall-rules create allow-http \

  --allow tcp:80 \

  --target-tags http-server

5. Visit:
http://<EXTERNAL_IP>


🗃️ 6. Connecting to Cloud SQL from Your App

1. Create Cloud SQL Instance

bash

 

gcloud sql instances create mydb \

  --database-version=MYSQL_8_0 \

  --tier=db-f1-micro \

  --region=us-central

2. Create User & Database

bash

 

gcloud sql users set-password root --host=% --instance=mydb --password=your-password

gcloud sql databases create appdata --instance=mydb

3. Connect via App Engine (using Cloud SQL Proxy)
Add to app.yaml:

yaml

 

beta_settings:

  cloud_sql_instances: your-project:us-central:mydb

Use connection string in your app (Python example):

python

 

pymysql.connect(unix_socket='/cloudsql/your-project:us-central:mydb', ...)


📈 7. Enabling Monitoring and Logs

1. View Logs

bash

 

gcloud logging read "resource.type=gae_app"

2. Open Logs Explorer:

  • Go to Cloud Console → Logging → Logs Explorer

3. Create Uptime Checks

  • Go to Cloud Monitoring → Uptime Checks
  • Enter URL and set alerting policy

8. Summary Table – Deployment Options

Method

Use Case

Scales Automatically

Management Level

Cloud Storage

Static websites, files

N/A

Fully managed

App Engine

Web apps with standard runtimes

Fully managed

Cloud Run

Docker apps, APIs

Fully managed

Compute Engine

Full VM control, legacy apps

Manual

Self-managed


🎯 Final Thoughts

GCP offers multiple deployment options to suit every need—from static websites to containerized microservices. With simple commands and intuitive interfaces, you can launch apps in minutes and scale them globally.

Once your app is running, make sure to monitor it using Cloud Monitoring, optimize costs with budgets, and secure your endpoints with IAM and firewall rules.


In the next chapter, we’ll explore IAM, billing management, and cloud security best practices.

Back

FAQs


❓1. What is Google Cloud Platform (GCP)?

Answer:
GCP is Google’s suite of cloud computing services that provides infrastructure, platform, and serverless environments to build, deploy, and scale applications using the same technology that powers Google Search, YouTube, and Gmail.

❓2. Is Google Cloud free to use?

Answer:
Yes. GCP offers a $300 free credit for 90 days for new users and an Always Free Tier for services like Cloud Storage, BigQuery, and Compute Engine (1 f1-micro instance in select regions).

❓3. How do I start using GCP?

Answer:
To get started, create a Google Cloud account at cloud.google.com, set up your first project, enable billing, and explore the Console or use the gcloud CLI for resource management.

❓4. What’s the difference between Compute Engine and App Engine?

Answer:

  • Compute Engine gives you full control over virtual machines (IaaS).
  • App Engine is a fully managed PaaS that handles infrastructure, scaling, and deployments automatically.

❓5. What is a GCP project?

Answer:
A GCP project is a container for resources like VMs, buckets, APIs, and billing. It isolates services and permissions and helps organize workloads across environments.

❓6. Which programming languages are supported by GCP?

Answer:
GCP supports many languages including Python, Java, Go, Node.js, Ruby, PHP, C#, and .NET, depending on the service used (App Engine, Cloud Functions, Cloud Run, etc.).

❓7. What tools are used to manage GCP?

Answer:
You can manage GCP via:

  • Google Cloud Console (UI)
  • Cloud Shell (browser-based CLI)
  • gcloud CLI
  • REST APIs
  • Terraform and Deployment Manager for infrastructure as code

❓8. What is BigQuery used for?

Answer:
BigQuery is a serverless data warehouse that allows you to store and analyze large datasets using SQL. It’s ideal for data analytics, reporting, and business intelligence.

❓9. Is GCP good for hosting websites?

Answer:
Yes. GCP offers multiple options to host websites:

  • Static websites via Cloud Storage + CDN (Cloud CDN)
  • Dynamic web apps using App Engine or Cloud Run
  • Custom VMs via Compute Engine

❓10. Does GCP offer certifications?

Answer:
Yes. Google Cloud offers certifications like:

  • Cloud Digital Leader (beginner)
  • Associate Cloud Engineer
  • Professional Cloud Architect
  • Data Engineer, DevOps Engineer, and more, to validate your cloud skills.