/mountains-service-pi

A small example microservice based in Python. This project is referenced by this Katacoda scenario.

Primary LanguagePython

Python Microservice in Distilled Containers

This is a small example microservice based in Python. It demonstrates some basic REST based commands that maintain a list of mountain information. The REST calls setup basic CRUD instructions to create, read, update, and delete information about mountains. Why mountains? It's arbitrary and generic. This service does not connect to a database, but provides a skeleton where that certainly could be added as a teaching exercise. The purpose is to explore a basic microservice that servers JSON REST and is packaged into a container. The container is intended to be used for teaching about Kubernetes in a Katacoda scenario. For a better understanding of this project, follow this Katacoda scenario.

There are several web frameworks in Python to choose from, and for this example the FastAPI with uvicorn were chosen.

More could be added to this skeleton by following this helpful example from Paurakh Sharma Humagain.

The slimming of the Dockerfile was inspired by two projects.

  1. The creator of FastAPI, Sebastián Ramírez, also created a project with efficient base containers for FastAPI.

  2. Wojtek @suda Siudzinski blog on Production-ready Django 3 ASGI Docker image and accompanying source code.

Running Instructions

There are a few Dockerfiles that will package the Python microservice differently. They all can be run using the ./try.sh script.

./try.sh bloated ./try.sh slim

References

How to Build Slim Docker Images Fast

Production-ready Django 3 ASGI Docker image

Microservice in Python using FastAPI

FastAPI

FastAPI Containers

Example Dockerfile

Example Dockerfile