Readiness Check

This tutorial guides you through the process of using the Node Readiness endpoint, which provides a reliable way to determine if Kong Gateway is ready to serve user requests.

The readiness check endpoint returns a 200 OK response when Kong Gateway is ready, or a 503 Service Temporarily Unavailable response when it’s not. This is useful for load balancers and other tools that need to monitor the readiness of Kong instances. When Kong is not ready, the endpoint responds back with a message field with the reason for unreadiness. This can be helpful to debug situations where the user expects that the node should be ready but is not.

Note: The readiness endpoint does not return detailed information about the node status.

Prerequisites

  • Kong Gateway
  • A basic understanding of Kong Gateway configuration and deployment modes (traditional, DB-less, and hybrid)

Understanding the Node Readiness endpoint

Before diving into the steps, it’s important to understand the purpose of the Node Readiness endpoint and how it determines whether a Kong instance is ready or not.

Traditional mode

In traditional mode, the endpoint returns 200 OK when all of the following conditions are met:

  1. Successful connection to the database
  2. All Kong workers are ready to route requests
  3. All routes and services have their plugins ready to process requests

Hybrid mode (data_plane role) or DB-less mode

In Hybrid mode (data_plane role) or DB-less mode, the endpoint returns 200 OK when the following conditions are met:

  1. Kong has loaded a valid and non-empty config (kong.yaml)
  2. All Kong workers are ready to route requests
  3. All routes and services have their plugins ready to process requests

Hybrid mode (control_plane role)

In Hybrid Mode (control_plane role), this endpoint returns 200 OK when the following condition is met:

  1. Successful connection to the database

Enabling the Status endpoint

In order to use the Node Readiness endpoint, make sure that you have enabled the Status API server (disabled by default) via the status_listen configuration parameter.

Example kong.conf:

  1. status_listen = 0.0.0.0:8100

Using the Node Readiness endpoint

Once you’ve enabled the Node Readiness endpoint, you can send a GET request to check the readiness of your Kong Gateway instance:

  1. # Replace `localhost:8001` with the appropriate host and port for
  2. # your Status API server
  3. curl -i http://localhost:8001/status/ready

If the response code is 200, the Kong Gateway instance is ready to serve requests:

  1. HTTP/1.1 200 OK
  2. Date: Thu, 04 May 2023 22:00:52 GMT
  3. Content-Type: application/json; charset=utf-8
  4. Connection: keep-alive
  5. Access-Control-Allow-Origin: *
  6. Content-Length: 19
  7. X-Kong-Admin-Latency: 3
  8. Server: kong/3.3.0
  9. {
  10. "message": "ready"
  11. }

If the response code is 503, the Kong Gateway instance is unhealthy and/or not yet ready to serve requests:

  1. HTTP/1.1 503 Service Temporarily Unavailable
  2. Date: Thu, 04 May 2023 22:01:11 GMT
  3. Content-Type: application/json; charset=utf-8
  4. Connection: keep-alive
  5. Access-Control-Allow-Origin: *
  6. Content-Length: 43
  7. X-Kong-Admin-Latency: 3
  8. Server: kong/3.3.0
  9. {
  10. "message": "failed to connect to database"
  11. }
  1. HTTP/1.1 503 Service Temporarily Unavailable
  2. Date: Thu, 04 May 2023 22:06:58 GMT
  3. Content-Type: application/json; charset=utf-8
  4. Connection: keep-alive
  5. Access-Control-Allow-Origin: *
  6. Content-Length: 70
  7. X-Kong-Admin-Latency: 16
  8. Server: kong/3.3.0
  9. {
  10. "message": "no configuration available (empty configuration present)"
  11. }

Updating Readiness Probes

If you’re using Kubernetes or Helm, you may need to update the readiness probe configuration to use the new Node Readiness endpoint. Modify the readinessProbe section in your configuration file to look like this:

  1. readinessProbe:
  2. httpGet:
  3. path: /status/ready
  4. # Make sure to replace the port number with the one you
  5. # configured for the Status API Server.
  6. port: 8100
  7. initialDelaySeconds: 10
  8. periodSeconds: 5

See also

For more information on Kong and related topics, check out the following resources: