Difficulty: beginner
Estimated Time: 15 minutes

The goal of this interactive scenario is to deploy two Java microservices to Kubernetes and check their health.

The online terminal is a pre-configured Linux environment that can be used as a regular console (you can type commands). Clicking on the blocks of code followed by the ENTER sign will execute that command in the terminal.

For information regarding setting up a Kubernetes cluster please look at the following tutorial: Setting up a cluster

Great Work! You're done!

You have used MicroProfile Health to create an endpoint that reports on your Java microservice’s status. Then, you observed how Kubernetes uses the /health endpoint with the readiness probe to keep your microservices running smoothly.

If you would like to look at the code for these microservices follow the link to the github repository. For more information about the MicroProfile specification used in this tutorial, visit the MicroProfile website with the link below.

Github repository MicroProfile.io

Interactive Tutorial - Configuring Readiness Probe for Java Microservice

Step 1 of 4

Deploy Java microservices

Let's begin by ensuring our Kubernetes environment is set up by running the following command:

kubectl version

If the command returns the versions of your kubectl client and cluster, the environment is configured. Otherwise, repeat the previous command until the command returns the versions.

Now that you have your Kubernetes cluster up and running, you can deploy your microservices using the following command:

kubectl apply -f kubernetes.yaml

While you are waiting for your services to start up, take a look at the provided kubernetes.yaml file that you have used to deploy your two Java microservices, by issuing the command below:

cat kubernetes.yaml

Here you can see configuration for two deployments and two services. The first deployment name-deployment has two replicas which means it will have two pods running. We also specify the Docker image name and the container ports we would like to map outside the container, 9080. This deployment contains a simple Java microservice that displays a brief greeting and the name of the container it runs in.

The second deployment ping-deployment does not specify any replicas as we only require one pod for this tutorial. This deployment pings the Kubernetes service that encapsulates the pod running the name microservice. This demonstrates how communication can be established between pods in your cluster.

For each deployment, you can find information relating to the readiness probe, provided by Kubernetes, underneath the ‘readinessProbe’ attribute. We have specified a delay of 15 seconds that will give the deployment sufficient time to start up. The polling period is set to 5 seconds so it will check the pods health every 5 seconds and if it gets one bad request it will mark that pod as unhealthy.

The Kubernetes readiness probes in these services are implemented using MicroProfile health. Issue the following command to check the health of your pods:

kubectl get pods

The microservices are fully deployed and ready for requests when the READY column indicates 1/1 for each deployment. Repeat the previous command until all deployments are ready before continuing to the next step.