Every application should contain at least two endpoints:
- readiness check,
- health check.
Readiness check should indicate when the app is ready to serve traffic. It should allow traffic when the app is correctly initialized. For example it should wait for the database connection to be established. The connection to cache or external API as well. This probe allows to cut off the traffic in case the app is unable to handle it. For example when downstream service is down or the app is processing large data. In this case you don’t want to kill the app, but you don’t want to handle these requests as well.
The liveness probe (or healthcheck) is used to periodically check the state of the app. The kubelet uses it to check when to restart the container.
The liveness probe should be as lightweight as possible. It should give information if the app is responsive, whether load balancer can open a connection and have a response in given time.
Here I will show a simple readiness and liveness probe. The common endpoints for those probes are
$ go run main.go &; while sleep 1; do curl localhost:8080/ready; done  14906 curl: (7) Failed to connect to localhost port 8080 after 5 ms: Couldn't connect to server not ready not ready not ready not ready ok ok
Here you can find an example Pod manifest to deploy our app with both probes.
Using third party library
Go ecosystem provides several packages, which makes the job easier to create the healthchecks.