Gateway health checks
Enable a health check plugin on your gateway proxy to respond with common HTTP codes.
About
K8sGateway includes an HTTP health checking plug-in that you can enable for a gateway proxy listener. This plug-in responds to health check requests directly with either a 200 OK
or 503 Service Unavailable
message, depending on the current draining state of Envoy.
Before you begin
-
Follow the Get started guide to install K8sGateway, set up a gateway resource, and deploy the httpbin sample app.
-
Get the external address of the gateway and save it in an environment variable.
export INGRESS_GW_ADDRESS=$(kubectl get svc -n gloo-system gloo-proxy-http -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}") echo $INGRESS_GW_ADDRESS
kubectl port-forward deployment/gloo-proxy-http -n gloo-system 8080:8080
Configure a health check on a gateway
-
Create an HTTPListenerOption resource to configure a health check path for the HTTP or HTTPS listener on the gateway. You can define any path, such as
/check/healthz
.kubectl apply -f- <<EOF apiVersion: gateway.solo.io/v1 kind: HttpListenerOption metadata: name: healthcheck namespace: gloo-system spec: targetRefs: - group: gateway.networking.k8s.io kind: Gateway name: http options: healthCheck: path: <path> EOF
-
To test the health check, drain the Envoy connections by sending an
HTTP POST
request to the/healthcheck/fail
endpoint of the Envoy admin port.- Port-forward the
gloo-gateway-http
deployment on port 19000.kubectl port-forward deploy/gloo-proxy-http -n gloo-system 19000 &
- Send an
HTTP POST
request to the/healthcheck/fail
endpoint. This causes Envoy connections to begin draining.curl -X POST 127.0.0.1:19000/healthcheck/fail
- Port-forward the
-
Send a request to the health check path. Because Envoy is in a draining state, the
503 Service Unavailable
message is returned.curl -i $INGRESS_GW_ADDRESS:8080/<path>
curl -i localhost:8080/<path>
-
After you finish testing, resume Envoy connections by sending an
HTTP POST
request to the/healthcheck/ok
endpoint of the Envoy admin port.curl -X POST 127.0.0.1:19000/healthcheck/ok
-
Send another request to the health check path. Because Envoy is operating normally, the
200 OK
message is returned.curl -i $INGRESS_GW_ADDRESS:8080/<path>
curl -i localhost:8080/<path>
-
Stop port-forwarding the
gloo-gateway-http
deployment.lsof -ti:19000 | xargs kill -9
Cleanup
You can remove the resources that you created in this guide.kubectl delete HttpListenerOption healthcheck -n gloo-system