OpenShift Deployment
NotesBuild a container image of the application and deploy it on OpenShift.
The following section covers deploying the application on Red Hat OpenShift, the Kubernetes platform from Red Hat. One of the key motivations for using FastAPI, as mentioned at the very start of this guide, is how simple it is to put the application in a container, and OpenShift is a great place to run containers.
We’ll work through it in stages:
- Container Image: build an image of the application with Podman, and run it locally, the way OpenShift will.
- OpenShift Local: run a small OpenShift cluster on your own computer (or use the free Developer Sandbox instead).
- Image Registry: push the image to OpenShift’s built-in registry.
- Deploy: run the application with a Deployment, persistent storage, configuration and secrets, and make it public with a Route.
- Builds: have OpenShift build the image itself, straight from Git.
- Monitoring: have OpenShift’s own monitoring scrape the application’s metrics.
Why OpenShift?#
OpenShift is Kubernetes with the pieces you’d otherwise have to assemble yourself: a web console, an image registry, builds, routes with TLS, monitoring and logging, and secure defaults. In particular, it runs every container as a random, unprivileged user, which the container image needs to allow for, as you’ll see.
Everything in this section uses standard Kubernetes resources (Deployments, Services, PersistentVolumeClaims, ConfigMaps and Secrets), plus two OpenShift additions: Routes, and builds. The YAML files are in the example code, in the openshift directory.