A step-by-step introduction to running your app in Kubernetes. For Generation X, but not only. Part I
I have been working in the software engineering industry for more than two decades. In this series of blog posts, I will try to do my best and turn a simple API service from an old-fashioned application running on my laptop into a modern microservice running in the Kubernetes cluster. Also, we will try to make the app less old-fashioned (aka, cloud-native). Step by step. One step at a time.
Part One. Old-fashioned app.
You’ll need a modern Python version properly set up on your machine. I’ll leave outside of this article how to set up it. There are plenty of good guides on the Web.
Create a file requirements.txt with the following content:
fastapi
uvicorn[standard]
pylint
And install those requirements
pip3 install -r requirements.txt
Create a file app.py with the code of the application
import uvicorn
from fastapi import FastAPI
from fastapi.logger import logger
app = FastAPI()
@app.get("/hello")
def hello():
logger.warning('Request!')
return {"Hello": "World"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=9000)
After starting the application you should see something like:
And you can send the first request to your API:
That’s it. Your application is up and running. Now you can copy it (there were no good deployment tools, at least well adopted by the community, during the old times) to your favorite hoster. But, please, remember — it should be old-fashioned. So, blow the dust from your favorite FTP client, and find that piece of paper with login and password from the account for a bare-metal server on collocation…