Python Flask App on Section
Learn how to run a "Hello World" Python Flask app at the edge for low latency and high availability. You can use our repo as a template, or perform the steps yourself using the Kubernetes dashboard or kubectl commands.
Option 1 - Copy Our GitHub Repo
Make a new repo from our template: in your browser visit https://github.com/section/python-flask-template and select
Use this template (don't clone, don't fork, but use the template). Choose yourself as an owner, give it a name of your choice, and make it be Public (not Private).
- In your new GitHub repo, under Settings > Secrets > Actions, use
New repository secretto add these two:
- Make any change to
./helloworld.pyand watch your changes go live.
Option 2 - Step by Step
Following are step-by-step instructions to deploy a Python Flask "Hello World" application to the edge on Section. We'll Dockerize it, and deploy it on Section.
- You need Docker installed so that you can build a docker image.
Create the Python Flask App
Create a new directory for your app.
helloworld.py with the following code.
from flask import Flask
app = Flask(__name__)
return 'Hello World from Python Flask on Section!'
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=8080)
requirements.txt with the following content to specify the version of Flask you are using.
Let's build the container image that we'll deploy to Section. First make a
Dockerfile in your directory with the following content.
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "helloworld.py"]
Build and tag it.
docker build . -t ghcr.io/YOUR_GITHUB_USERNAME/my-flask-app:prod
Launch it locally to test it.
docker run -p 8080:8080 ghcr.io/YOUR_GITHUB_USERNAME/my-flask-app:prod
Push it to GitHub Packages. This makes it available to Section.
docker push ghcr.io/YOUR_GITHUB_USERNAME/my-go-app:prod
Be sure to make it public. To see your packages and make this change, visit
Next, use the Create Project command in the Section Console in order to deploy your new container. Use the image name
ghcr.io/YOUR_GITHUB_USERNAME/my-flask-app:prod with port 8080.
See the pods running on Section's network with either the Kubernetes dashboard or
kubectl get pods -o wide. The
-o wide switch shows where your app is running according to the default AEE location optimization strategy. Your app will be optimally deployed according to traffic. In lieu of significant traffic, your deployment will be made to default locations.
kubectl logs POD to see the log message reporting that the server is listening on port 8080 (
App listening at http://localhost:8080)
See What You've Built
See the "Hello World!" app you've built by visiting the
YOUR.DOMAIN.COM according to your DNS and HTTPS configuration.