Flask + Redis HTTP Server
This guide explains how to create and deploy a Flask app with a Redis database on Unikraft Cloud. The example consists of two services: a Flask web server that increments a page view counter stored in Redis.
To run this example, follow these steps:
- Install the CLI. Use the unikraft CLI or the legacy kraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. Alternatively, you can also directly set up and use BuildKit, see the quick start.
The unikraft CLI is the current standard, while kraft is the legacy version. Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.
- Clone the
examplesrepository andcdinto theexamples/httpserver-flask-redisdirectory:
Code
Make sure to log into Unikraft Cloud and pick a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
Deploy Redis
First, deploy the Redis instance.
Redis is an internal service (not publicly accessible), reached via the redis.internal domain:
The output shows the Redis instance details:
Deploy Flask
Next, deploy the Flask web server.
It connects to Redis using the REDIS_HOST and REDIS_PORT environment variables:
The output shows the Flask instance details:
In this case, the Flask instance address is https://withered-cherry-xfcrfp93.fra.unikraft.app.
It's different for each run.
Test the deployment
Use curl to query the Flask instance.
Each request increments the Redis counter:
Code
Code
Code
Code
You can list information about the instances by running:
Clean up
When done, remove the instances:
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Code
Or visit the CLI Reference.