Implementing Health Checks With MicroProfile and Istio

DZone 's Guide to

Implementing Health Checks With MicroProfile and Istio

When running cloud-native applications in orchestration frameworks, microservices need to report whether they are ready and live.

· Microservices Zone ·
Free Resource

When running cloud-native applications in the orchestration framework Kubernetes and the service mesh Istio, microservices need to report whether they are ready and live. Kubernetes needs to know this to restart containers if necessary. Istio needs to know this information to define where to route requests to.

With the Kubernetes livenessProbe it is determined whether, as the name indicates, the pod is live. Pods that are live might not be ready though, for example, when they just started and still need to load data. That's why there is a second probe, the readinessProbe.

I've implemented some sample code that shows how to develop these health checks with Eclipse MicroProfile.

Get the code of cloud-native-starter from GitHub.

Here is the Java code which tells the 'articles' service that the microservice is ready.

import org.eclipse.microprofile.health.Health;
import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import javax.enterprise.context.ApplicationScoped;

public class HealthEndpoint implements HealthCheck {

    public HealthCheckResponse call() {
        return HealthCheckResponse.named("articles").withData("articles", "ok").up().build();

In the Kubernetes YAML file the URLs of the livenessProbe and the readinessProbe are defined.

kind: Deployment
apiVersion: apps/v1beta1
  name: articles
  replicas: 1
        app: articles
        version: v1
      - name: articles
        image: articles:1
        - containerPort: 8080
            command: ["sh", "-c", "curl -s http://localhost:8080/"]
          initialDelaySeconds: 20
            command: ["sh", "-c", "curl -s http://localhost:8080/health | grep -q articles"]
          initialDelaySeconds: 40
      restartPolicy: Always

If you want to run this demo yourself in Minikube, get the code from GitHub and invoke these commands:

$ git clone https://github.com/nheidloff/cloud-native-starter.git
$ scripts/check-prerequisites.sh
$ scripts/deploy-articles-java-jee.sh
$ kubectl get pods --watch
$ minikube dashboard

To learn more about health checks, take a look at these articles:

microservices ,microservices tutorial java ,health checks ,microservices performance

Published at DZone with permission of Niklas Heidloff , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}