Deploying Python Web Apps on Google Cloud Kubernetes Engine with Terraform

Deployment workflow.

Before you get started, you need to install environment binaries. In this example the first few steps illustrate how to setup and configure binaries on Mac OSX/Linux.

Stack used: Terraform, kubectl, YAML, Redis cluster, Python & Go Lang

Here what is needed before you get started.

  1. terraform executable

2. gcloud binaries

3. kubectl/minikube

on mac using homebrew

$ brew install kubectl

Install Docker

4. Setup gcloud creds

5. It is time to write your declarative IAC code to define your GCP infrastructure provider.

6. Define your Kubernetes cluster tf declaration.

7. Initialize terraform:

8. Before apply dry run terraform with “plan” option

9. Apply myplan to continue

10. Set project name and get container authentication creds.

Deploying Redis cluster to GKE

11. Redis Master config:

12. Deploy redis master to GKE

13. Create Redis Master service

Config file:

14. Redis Slave config:

Deploy slave pods and service

Deploying WebApp container to GKE

  1. Dockerfile (webApp)

2. Create docker tag, and push it to Google Cloud Registry (GCR).

3. WebApp deployment

pod declaration :

service declaration:

Testing Redis connection

Testing Python WebApp

Automate this into CI/CD pipelines or manually schedule

Check pod logs

Troubleshooting Kube service

I am a software engineering manager, and cloud architect who design, build, deploy, scale ,simplify and cost optimize platform architecture.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store