Deploy FastAPI microservice in Kubernetes via OpenFaaS

9/8/2021

I have a big application structured with FastAPI (with many routers), that runs in AWS Lambda. I want to migrate it to a container inside Kubernetes. From my research, OpenFaaS is a great solution. However I can't find documentation about how to do this.

Does anyone has references or a better solution?

-- Bemojo
aws-lambda
fastapi
kubernetes
openfaas
python

2 Answers

9/9/2021

If you are using the python or Ruby

You can create the docker file and use it for creating the docker images and simply deploy it on Kubernetes.

FROM ruby:2.7-alpine3.11

WORKDIR /home/app
COPY    .   .

RUN bundle install

CMD ["ruby", "main.rb"]

For OpenFass they have provided good labs with documentation to create the Async function etc.

Labs : https://github.com/openfaas/workshop

If you are looking for examples you can check out the official repo only : https://github.com/openfaas/faas/tree/master/sample-functions

Extra

There is also another good option Knative or Kubeless

You can find the python Kubeless example and CI/CD example : https://github.com/harsh4870/kubeless-kubernetes-ci-cd

-- Harsh Manvar
Source: StackOverflow

10/19/2021

Try use a template to build an upstream FastAPI application as an OpenFAAS function. This will create a docker image you can run and deploy in your Kubernetes cluster.

You can see how to do so in the following github repo

-- Sara Rodríguez
Source: StackOverflow