Deploy your Flask app on the Google Cloud Platform

From localhost to the world wide web with GCP

Jesko Rehberg
Geek Culture

--

Together you are less alone (Photo by Alina Grubnyak)

Assuming you have successfully converted your Python project into a Flask app under localhost.

if __name__ == "__main__":
app.run()

In five simple steps, we will deploy this app (main.py in this example) to the Google Cloud Platform. This will make your Flask app accessible from anywhere in the world over the Internet.

Solution

One approach to deploying the Flask (localhost) app on the Google Cloud Platform (GCP) is to use Google App Engine (GAE).

  1. Create a GCP project: If you don’t already have a GCP account, create one and create a new project.
  2. Set up the Cloud SDK: Install the Cloud SDK on your local machine if you haven’t already.
  3. Set up the app.yaml file: Create an app.yaml file in the root directory of your project. This file is used to configure your GAE environment. Here’s an example:
runtime: python39
entrypoint: gunicorn -b :$PORT main:app

handlers:
- url: /.*
script: auto

This example specifies the Python 3.9 runtime and uses Gunicorn as the server. The entrypoint line specifies the command to start the server. The handlers section…

--

--

Jesko Rehberg
Geek Culture

Data scientist at https://en.digitalsalt.de/. Views and opinions expressed are entirely my own and may not necessarily reflect those of my company