06 Deploying Applications To Google Cloud
06 Deploying Applications To Google Cloud
to Google Cloud
Stephanie Wong
Developer Advocate, Google Cloud
Let me give you a high-level overview of how you could decide on the most suitable
platform for your application.
First, ask yourself whether you have specific machine and OS requirements. If you
do, then Compute Engine is the platform of choice.
If you have no specific machine or operating system requirements then the next
question to ask is whether you are using containers. If you are, then you should
consider Google Kubernetes Engine or Cloud Run, depending on whether you want
to configure your own Kubernetes cluster.
If you are not using containers, then you want to consider Cloud Functions if your
service is event-driven, and App Engine if it’s not.
We’ll talk through each of these services in this module and you will get to explore
them in a lab.
Let’s begin by talking about Compute Engine, which is Google Cloud’s infrastructure
as a service (or IaaS) offering.
Use Compute Engine when you need complete
control over operating systems, for apps that are not
containerized or self-hosted databases
ZONE A
Cloud Server
DNS Compute Engine
Static Content
Autoscaling Cloud Storage
Cloud Load
Balancing
ZONE B
Dynamic Content
Server Cloud SQL
Cloud Compute Engine
CDN
Autoscaling
Compute Engine is a great solution when you need complete control over your
operating systems, or if you have an application that is not containerized, an
application built on a microservice architecture, or an application that is a database.
Instance groups and autoscaling as shown on this slide allow you to meet variations
in demand on your application. Let’s take a closer look at instance groups.
Managed instance groups create VMs based on
instance templates
The virtual machines in a managed instance group are created by an instance group
manager. Using a managed instance group offers many advantages, such as
autohealing to re-create instances that don’t respond and creating instances in
multiple zones for high availability.
Use one or more instance groups as the backend for
load balancers
I recommend using one or more instance groups as the backend for load balancers. If
you need instance groups in multiple regions, use a global load balancer, and if you
have static content, simply enable Cloud CDN as shown on the right.
Agenda
Google Cloud Infrastructure as a
Service
Let’s go through the other deployment platforms: GKE, Cloud Run, App Engine, and
Cloud Functions.
Google Kubernetes Engine (GKE) automates the
creation and management of compute infrastructure
● Kubernetes clusters have a
collection of nodes.
● In GKE, nodes are Compute Pod Pod Pod
Engine VMs. Container Container Container
This diagram on the right shows the layout of a Kubernetes cluster. A cluster consists
of at least one cluster control plane and multiple worker machines that are called
nodes. These control plane and node machines run the Kubernetes cluster
orchestration system. Pods are the smallest, most basic deployable objects in
Kubernetes. A pod represents a single instance of a running process in a cluster.
Pods contain one or more containers, such as Docker containers, that run the
services being deployed. You can optimize resource use by deploying multiple
services to the same cluster.
Cloud Run allows you to deploy containers to
Google managed Kubernetes clusters
● Cloud Run allows you to use
Kubernetes without the cluster
management or configuration
code.
● Apps must be stateless.
● Need to deploy apps using
Docker images in Container
Registry.
● Can also use Cloud Run to
automate deployment to your
own GKE cluster.
Cloud Run, on the other hand, allows you to deploy containers to a Google-managed
Kubernetes cluster. A big advantage is that you don’t need to manage or configure the
cluster. The services that you deploy must be stateless, and the images you use must
be in Container Registry. Cloud Run can be used to automate deployment to Anthos
GKE clusters. You should do this if you need more control over your services,
because it will allow you to access your VPC network, tune the size of compute
instances, and run your services in all GKE regions. The screenshot on the right
shows a Cloud Run configuration where the container image URL is specified along
with the deployment platform, which can be fully managed Cloud Run or Cloud Run
for Anthos.
App Engine was designed for microservices
App Engine is a fully managed, serverless application platform supporting the building
and deploying of applications. Applications can be scaled seamlessly from zero
upward without having to worry about managing the underlying infrastructure. App
Engine was designed for microservices. For configuration, each Google Cloud project
can contain one App Engine application, and an application has one or more services.
Each service can have one or more versions, and each version has one or more
instances. App Engine supports traffic splitting so it makes switching between
versions and strategies such as canary testing or A/B testing simple.
The diagram on the right shows the high-level organization of a Google Cloud project
with two services, and each service has two versions. These services are
independently deployable and versioned.
Static Content
Cloud Storage
Dynamic Content
Frontend App Batch App
Cloud SQL
App Engine App Engine
Memcache
Cloud
Tasks
This could be an example of a retailer that sells online. Here App Engine serves as
the frontend for both web and mobile clients. The backend of this application is a
variety of Google Cloud storage solutions with static content such as images stored in
Cloud Storage, Cloud SQL used for structured relational data such as customer data
and sales data, and Firestore used for NoSQL storage such as product data. Firestore
has the benefit of being able to synchronize with client applications.
Memcache is used to reduce the load on the datastores by caching queries, and
Cloud Tasks are used to perform work asynchronously outside a user request (or
service-service request). There’s also a batch application that generates data reports
for management.
Cloud Functions is great way to create loosely
coupled, event-driven microservices
● Can be triggered by changes in a storage bucket, Pub/Sub messages,
or web requests
● Completely managed, scalable, and inexpensive
Events
Image Bucket OCR Cloud
Cloud Storage Cloud Functions Vision API
File
Upload
This sequence illustrates a typical use case of Cloud Functions for event-based
processing.
Lab Objectives
● Deploy to App Engine
Deploying Apps to ● Deploy to Google Kubernetes
In the first lab of this course, you used Cloud Build to create Docker images and store
those images in Container Registry. If you follow the 12-factor best practices when
writing your applications, you should be able to create applications that are portable
across different cloud providers and also portable between different deployment
services provided by the cloud. That’s why in this lab, you deploy code to App Engine,
Google Kubernetes Engine, and Cloud Run. Let me quickly go over why we chose
those services for this lab:
Kubernetes can get pretty complicated though. That’s where Cloud Run comes in.
Cloud Run allows you to deploy your own stateless, Dockerized services onto
Kubernetes clusters that are managed by Google. Google Cloud takes care of the
hard parts of managing the cluster and configuring the load balancers, autoscalers,
and health checkers, so that you just focus on the code.
Deploying a single application on all of these compute platforms might help you
choose the right platform for your own services.
Lab review
Deploying Apps to
Google Cloud
In this lab you saw how to deploy an application to App Engine, GKE, and Cloud Run.
Hopefully, this lab gave you a better feel for how each of these compute platforms
works and will help you choose the right platform for your own services.
I recommend that you follow the 12-factor best practices that we covered earlier in the
course, automate as much as possible by using continuous integration and
infrastructure as code tools, and containerize your services using Docker. If you do
that, your apps will be very portable, and deployment will become easier and more
flexible, no matter which compute platform you use.
You can stay for a lab walkthrough, but remember that Google Cloud's user interface
can change, so your environment might look slightly different.
Review
Deploying Applications
to Google Cloud
Again, each of these choices has advantages and disadvantages. Make sure you
understand each one so that you can make an informed decision when deploying
your services.