Docker container status sync with spring boot app

Viewed 37

I pack my spring boot apps in Docker containers and deploy to Kubernettes. I want the container status to be "up" only when the spring boot application is up, by default the container is "up" and spring boot app is still starting. Is that possible?

1 Answers

what you need is a Health Check Endpoint, so Kubernetes (but also locally Docker) can test if your application is ready or not.

Consider using Spring Actuator and enable the health endpoint. You can find the information here at this link: https://www.vojtechruzicka.com/spring-boot-actuator/

Once you have the Actuator active, you can configure in your Kubernetes Deployment YAML the startup-, readiness- and livenessProbe and the Docker HEALTHCHECK keyword

The startupProbe is useful for slow starting applications, so you might want to configure periodSeconds and failureThreshold to high values, so that the application will be declared "failed" if the failureThreshold*periodSeconds is passed, but if it's started correctly, then will liveness and readiness Probes activated

Related