DEV Community

Cover image for helm chart for fastAPI
Harish Aravindan
Harish Aravindan

Posted on • Updated on

helm chart for fastAPI

what is it about

packaging the fastapi as docker image and deploying as helm chart

Building docker image

Clone the repository

https://github.com/uptownaravi/LearnfastAPI.git
Enter fullscreen mode Exit fullscreen mode

change directories into /FastAPI_HelmChart/
in the Dockerfile we have a ubuntu base image on which we build the layers to install application and dependencies.

Using my sample application from previous blog
https://dev.to/harisharavindan/learning-fastapi-with-a-sample-python-library-5f2n

build the image

docker build . -t fast:v2 
Enter fullscreen mode Exit fullscreen mode

Docker image built is stored in github package ( ref https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry )

ghcr.io/uptownaravi/fast:v2
Enter fullscreen mode Exit fullscreen mode

any changes required can be done to the dockerfile and build a new image from that

Creating an Helm chart

have created a basic helm chart which uses the image built from the above dockerfile

change directories in the cloned repository folder

cd FastAPI_HelmChart/helmChart-fastAPI/
Enter fullscreen mode Exit fullscreen mode

explore the chart templates and values.

  • we have set the docker image to ghcr.io/uptownaravi/fast:v2
  • health check is at localhost:80/health
  • service is exposed at 80 as we had set that in the dockerfile

do a dry-run to check what is being installed
make sure to be in the directory FastAPI_HelmChart/helmChart-fastAPI/ where the Chart.yaml is available

helm install fastencode . --dry-run
Enter fullscreen mode Exit fullscreen mode

this installs the helm release fastencode which creates the deployment, service and related resources

check the details of the installed chart

kubectl get all -l='app.kubernetes.io/instance=fastencode'
Enter fullscreen mode Exit fullscreen mode

we can port-forward the service to check the app

kubectl port-forward svc/fastapi 8080:80
Enter fullscreen mode Exit fullscreen mode

this will forward the port 80 of the pod to the local host 8080
check fastapi ui with url http://localhost:8080/docs

to uninstall the release

helm uninstall fastencode
Enter fullscreen mode Exit fullscreen mode

Top comments (0)