# Application Health Checks

## Understand Liveness And Readiness

1. Open application URL and edit the URL by replacing `todo.html` with following path:

   * `/q/health`
   * `/q/health/live`
   * `/q/health/ready`

   Our To Do application already has the URLs which can be used to configure liveness and readiness probes.

   ![Health check URL](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-e5aff3efda6d948995fd6b66a813979c2ccf2a87%2Fhealthcheck00.png?alt=media)
2. Go back to OpenShift web console, scale the **todo-db** Pod to 0 and now open the application URL with `/q/health/live` and `/q/health/ready` paths.

   Ideally, the application is up and running that's why the `/q/health/live` returns `"status": "UP"`. However, it cannot connect to database so it's not ready to use or serve any incoming requests so the `/q/health/ready` returns `"status": "DOWN"`

   Kubernetes/OpenShift uses application health checks for traffic routing/load balancing, auto recovery/self-healing etc.

   ![Health check URL](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-e23c7d0887d20b8459eeed685da56ee0988814b0%2Fhealthcheck02.png?alt=media)
3. Scale the **todo-db** Pod back to 1 and wait until it's up and running.

## Setting The Probes

1. Select the **quarkus-todo-app** node, click on the **Actions** drowdownlist menu then select **Add Health Checks**.

   ![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-9d18a1c4a66a0061006837a7d1be61ea55d487b4%2Fhealthcheck01.png?alt=media)
2. Click **Add Readiness probe** link.

   ![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-b16d2f2b9ea0bca7c89387005739716a0b50b994%2Fhealthcheck03.png?alt=media)
3. Enter following inputs:

   * **Path:** `/q/health/ready`
   * **Initial delay:** `60`
   * **Timeout:** `5`

   Then click on the check button.

   ![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-9af6e5f1f854ace3049f72d8c85d561a89f19341%2Fhealthcheck04.png?alt=media)
4. Click **Add Liveness probe** link.

   ![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-0851a2bc4c6729ae46271ce1243e3919dfd2f13c%2Fhealthcheck05.png?alt=media)
5. Enter following inputs:

   * **Path:** `/q/health/live`
   * **Initial delay:** `60`
   * **Timeout:** `5`

   Then click on the check button.

   ![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-fb7f1661d298742ef37e5005642127a271138d37%2Fhealthcheck06.png?alt=media)
6. Click **Add** button.

   ![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-564e12e0eb2c7acefcf7e9edfc3b73a1fdc96459%2Fhealthcheck07.png?alt=media)
7. Deployment object will deploy a new Pod with health checks settings and terminate the old one. Wait until this completed.

   ![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-ebd91ed8730e73fa92a161c29629e62499bf42d8%2Fhealthcheck08.png?alt=media)
8. Go to **Resources** tab and click **View logs** link.

   ![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-2935fe5edd9d1b50295dfef8e7cefd41b86819ad%2Fhealthcheck09.png?alt=media)
9. You should see the logs indicate that `/q/health/ready` and `/q/health/live` URLs get called by `kube-probe` agent. Basically, Kubernetes/OpenShift will keep doing application health checks.

![Add health checks](https://4096465133-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fa3i2iCO0U9uw1JFkKW85%2Fuploads%2Fgit-blob-08a6a894fc385ae2c34b7af5f0a5e3bed2658652%2Fhealthcheck10.png?alt=media)
