I have a Python application of FastAPI based on Kubernetes.
I have configured the liveness, readiness, and startup probes on Kubernetes to run my 'healthz' endpoint for testing if the application is fine or not.
But if I am running a different heavy function, the healthz is unreachable by the liveness and then the pod crashes.
Here's my main FastAPI code:
from fastapi import FastAPI, HTTPException
from fastapi.responses import JSONResponse
import utils.logger as custom_log
from src.insights import insights_func
@app.get('/healthz', include_in_schema=False)
async def return_ok_status():
return JSONResponse(content={"status": "All Good!"}, status_code=200)
@app.get("/daily_checkup")
async def daily_checkup_status():
log.info("daily_checkup endpoint triggered")
try:
insights_func()
return JSONResponse(content={"status": "No stuck jobs!"}, status_code=200)
except Exception as e:
log.error("An error occurred: %s", str(e))
raise HTTPException(status_code=500, detail="Internal Server Error")
If I am running the 'daily_checkup' endpoint and the 'insight_func()' is running for more than 5 sec, then the liveness fails, and the pod crashes.
I know that I can increase the liveness timeout in the deployments file but there is a different way?
I don't want to rely on the liveness timeout. I want my 'healthz' endpoint to be reachable at all times and not depend if another function finished running or not.