Simple Container Deploys on Google Cloud Platform

Christopher Grant
3 min readJul 2, 2019

In the following demo we will walk through deploying the same sample container to the various Google Cloud compute platforms including Google Compute Engine, Google App Engine, Cloud Run, and Google Kubernetes Engine, with just a few commands.

Google has been working with containers internally since 2003. In 2006 they introduced cgroups to the linux kernel. Kubernetes and GKE are introduced to the world in 2014. Today Google deploys 4 billion containers every week. Containers are in Google’s DNA. Users of the Google Cloud Platform get access to this as well across GCP’s computing ecosystem.

Let’s jump in and do some deploys

Before you begin

First time GCP setup

If this is your first time using GCP you’ll need to get things setup before you jump into the demo. Setup a GCP Project Create a GCP project Download, install, and initialize the Cloud SDK. Acquire local credentials for authenticating with GCP services.

gcloud auth application-default login

Verify that your default project is correct.

gcloud config list

If the project ID listed in the output isn’t the project that you intended to use for this tutorial, set the project.

gcloud config set project [YOUR_PROJECT_ID]

where [YOUR_PROJECT_ID] is the ID of the project that you created or chose to use for this tutorial.

Prepare the Demo

Configure some defaults

gcloud config set compute/zone us-central1-a
gcloud config set run/region us-central1

Clone the sample repository.

git clone https://github.com/cgrant/hello-python-container.git
cd hello-python-container

Alternatively, you can download the sample as a zip file and extract it.

Build the sample app and push the container to the registry

export PROJECT=$(gcloud config get-value project)
gcloud builds submit --tag gcr.io/${PROJECT}/hellopython

Containers on Compute Engine

If you have any experience with Virtual Machines or Cloud IaaS this may seem obvious that you can install docker and run containers.

However it’s even easier than that on GCP. Google Compute Engine allows you to deploy an image directly to a traditional VM with a single command.

Deploy a container to GCE in one command

gcloud compute instances create-with-container hellopython \
--container-image gcr.io/${PROJECT}/hellopython

Containers on GKE

Google’s flagship managed kubernetes service GKE has been around for nearly 4 years and of course can run containers simply and easily.

Create your cluster in less than 5 minutes with a simple command

gcloud container clusters create mycluster

Then deploy your container again with one command

kubectl run hellopython --image gcr.io/${PROJECT}/hellopython

Containers on AppEngine

The AppEngine Flex runtime supports custom runtimes through the use of containers. Typically you would provide source code and a Dockerfile which would be built into an image for you and subsequently deployed.

However you may not know you can deploy images directly with app engine

We do need a very simple app.yaml

cat <<EOF >> app.yaml
runtime: custom
env: flex
EOF

Now deploy an image in one command

gcloud app deploy \
--image-url gcr.io/${PROJECT}/hellopython

Containers on Cloud Run

Cloud Run is a managed compute platform that enables you to run stateless containers invocable via HTTP requests. Cloud Run is serverless: it abstracts away all infrastructure management, so you can focus on what matters most — building great applications.

You have to try this demo for yourself it’s fantastic

Deploy your app to Cloud Run in one command

gcloud beta run deploy hellopython \
--image gcr.io/${PROJECT}/hellopython \
--allow-unauthenticated

In just a moment your service is up and running with a secured https endpoint.

Super fast super simple

Summary

Containers are becoming a staple of modern systems and migrating to containers is often a great choice. Taking advantage of the many runtime options available, you can deploy your containers to meet the unique workload needs.

--

--