Study your application
From Zero to Hero: Write your first Kubernetes charm > Study your application
A charm is an application packaged with all the logic it needs to operate in the cloud.
As such, if you want to charm an application, the first thing you need to understand is the application itself.
Of course, what exactly you’ll need to know and how exactly you’ll have to go about getting this knowledge will very much depend on the application.
In this part of the tutorial we will choose an application for you and tell you all you need to know about it to start charming. Our demo app is called ‘FastAPI Demo’ and we have designed it specifically for this tutorial so that, by creating a Kubernetes charm for it, you can master all the fundamentals of Kubernetes charming.
The FastAPI app was built using the Python FastAPI framework to deliver a very simple web server. It offers a couple of API endpoints that the user can interact with.
The app also has a connection to a PostgreSQL database. It provides users with an API to create a table with user names, add a name to the database, and get all the names from the database.
Finally, every time a user interacts with the database, our app writes logging information to the log file and also streams it to the stdout.
To summarize, our demo application is a minimal but real-life-like application that has external API endpoints, performs database read and write operations, and collects real-time metrics and logs for observability purposes.
The app source code is hosted at https://github.com/beliaev-maksim/api_demo_charm.
As you can see here, the app consists of primarily the following two files:
app.py, which describes the API endpoints and the logging definition, and
database.py, which describes the interaction with the PostgreSQL database.
Furthermore, as you can see here, the application provides a way to configure the output logging file and the database access points (IP, port, username, password) via environment variables:
The application is set up such that, once deployed, you can access the deployed IP on port 8000. Specifically:
|To get Prometheus metrics:||
|To get a Swagger UI to interact with API:||
Our app’s OCI image is at
See next: Set up your development environment
Last updated 5 months ago.