Introduction

In this article, I will try to list some container best practice with a Python HTTP API (using FastAPI) as an example.

In the containerized world, it’s not just that simple compare to the traditional VM deployment. You need to do some modify for your apps, otherwise you may encounter some problems such as: API failed rate ⬆️, API interrupted while doing deployment, etc.

  • Singleton
  • Image size
  • Graceful shutdown / Health check
  • Security
  • Logging

Concept - Pat & Cattle

pat_and_cattle

What is different between traditional and containerized deployment?

In the traditional deployment (e.g. VM deployment), we care about “every” VM and “every” app process.

However, in the containerized world, for high availability (HA) considerations, we may have many containers deployed across in different nodes. In these scenarios (e.g. Kubernetes), do you really care about “every” container’s “uptime” or “restart times”?

Or do you just care about if the whole service is healthy or not?