Skip to content

Latest commit

 

History

History
81 lines (60 loc) · 2.99 KB

README.adoc

File metadata and controls

81 lines (60 loc) · 2.99 KB

Health Probe

For this example we need a Kubernetes installation as described in INSTALLATION.adoc.

For our example for this pattern we are reusing our random-generator which also includes support for health checks.

To apply a Deployment with liveness and readiness check enables, use

kubectl create -f deployment.yml

This deployment introduces an artificial pause of 20 seconds before the application becomes ready. To monitor the readiness and liveness states you best open an extra terminal with running

kubectl get pods -w
NAME                                READY   STATUS        RESTARTS   AGE
random-generator-5856b5f774-54h6b   0/1     Running       0          5s
random-generator-5856b5f774-54h6b   1/1     Running       0          38s

The example apps expose to endpoints with which you can switch the state of the readiness and liveness checks. For simplicity reasons, we haven’t installed a Service or Ingress (but of course, you are free to do so of course !)

Instead we are using a simple port-forwarding directly to the pod to trigger the toggles:

# Port forward to Pod. "pod" is an alias to pick the full name of the pod (see INSTALL.adoc)
kubectl port-forward $(pod random-generator) 8080:8080 &

Now you can switch the readiness/liveness checks:

# Check liveness
curl -s http://localhost:8080/actuator/health | jq .
{
  "status": "UP"
}

# Switch liveness checks
curl -s http://localhost:8080/toggle-live

# Check liveness again
curl -s http://localhost:8080/actuator/health | jq .
{
  "status": "DOWN"
}

# Wait a bit and watch the pods. What happens after 2-3 mins ?
kubectl get pods -w

# Switch readiness off
curl -s http://localhost:8080/toggle-ready

# Watch the pods for 1-2 mins
kubectl get pods -w

# Toggle readiness back on
curl -s http://localhost:8080/toggle-ready

# Watch the pods again ...
kubectl get pods -w