In this tutorial, we'll show you how to deploy a simple Flask application on Google Cloud Run. Google Cloud Run is a serverless platform that allows you to run containerized applications quickly and easily.
We'll start by creating a simple Flask application and testing it locally. We are going to deploy the application using Cloud Shell.
By the end of this tutorial, you'll have a solid understanding of how to deploy a Flask application on Google Cloud Run and take advantage of its scalability, flexibility, and affordability.
So if you're ready to deploy your Flask application on Google Cloud Run, be sure to check out our tutorial. Don't forget to subscribe to our channel for more tutorials on Flask, Google Cloud, and other tools and technologies.
Keywords: Flask, Google Cloud Run, Docker, Containerization, Google Container Registry, Google Cloud SDK, gcloud, Deployment, Serverless, Scalability, Flexibility, Affordability
Hashtags: #Flask #GoogleCloudRun #Docker #Containerization #GoogleContainerRegistry #GoogleCloudSDK #gcloud #Deployment #Serverless #Scalability #Flexibility #Affordability
✅ Subscribe for more videos like this one
🔔 Click on the bell icon to be notified when I release a new video
👍 Please like my video!
⚠️ Join my channel to get access to perks: / @federicotartarini
🙏 Support my channel on Patreon at / federicotartarini
☕ Support my channel by buying me a coffee - www.buymeacoffee.com/FedericoT
✅ Let's connect:
🌍 My website - federicotartarini.github.io/
💻 GitHub - github.com/FedericoTartarini
Twitter - / federicotartar1
LinkedIn - / federico-tartarini
📝 Useful notes:
Google's official guide (contains source code): cloud.google.com/run/docs/qui...
👨💻 Source code:
Copy the following code in main.py
```
import os
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
name = os.environ.get("NAME", "World")
return "Hello {}!".format(name)
if _name_ == "__main__":
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
```
Copy the following code in Dockerfile
```
Use the official lightweight Python image.
hub.docker.com/_/python
FROM python:3.9-slim
Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
Install production dependencies.
RUN pip install Flask gunicorn
Run the web service on container startup. Here we use the gunicorn
webserver, with one worker process and 8 threads.
For environments with multiple CPU cores, increase the number of workers
to be equal to the cores available.
Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
```
Add the following code in .dockerignore
```
Dockerfile
README.md
*.pyc
*.pyo
*.pyd
_pycache_
.pytest_cache
```
🎥 Content of this video:
00:00 - What you will learn
02:55 - Create a new Project
04:33 - Create a new Flask web application
10:30 - Run the Flask app on the local emulator
14:00 - Deploy to Cloud Run
3 июл 2024