Master the container probe of SpringBoot-2.3: the basics

About the "SpringBoot-2.3 Containerization Technology" series

  • The "SpringBoot-2.3 Containerization Technology" series aims to learn and practice the latest containerization technology brought by version 2.3 together with everyone, so that our Java applications can be more adapted to the containerized environment, keeping up with the mainstream in the cloud computing era, and maintaining competitiveness ;
  • The whole series of articles is divided into two parts, the topic and the auxiliary part, the topic part is as follows:
  1. "Experiencing SpringBoot (2.3) Application Making Docker Image (Official Solution)" ;
  2. "Detailed explanation of SpringBoot (2.3) application making Docker image (official solution)" ;
  3. "Mastering SpringBoot-2.3 Container Probes: Basics" ;
  4. "Mastering SpringBoot-2.3 Container Probes: In-Depth Chapter" ;
  5. "Mastering the Container Probe of SpringBoot-2.3: Actual Combat" ;
  • The auxiliary part is a summary of some reference materials and memos, as follows:
  1. "Why do SpringBoot-2.3 mirroring solutions have multiple layers" ;
  2. "Set a non-root account to directly execute docker commands without sudo" ;
  3. "Development phase, rapid deployment of SpringBoot applications to K8S" ;

Introduction to SpringBoot Container Probe Series Articles

In order to make the application more adaptable to the containerized environment, SpringBoot2.3 releases new probe technology. The "Container Probe Mastering SpringBoot-2.3" series aims to learn and practice these new technologies with you, divided into three stages:

  1. Basic article: This article is to sort out and learn the relevant knowledge points of the container probe;
  2. In-depth articles : continue to in-depth study of probe-related knowledge points;
  3. Practical articles : deploy the springboot application in the kubernetes environment and use the latest probe technology;

Official information on probe characteristics

  • As shown in the red box in the figure below, the container probe feature of version 2.3 has been released as early as the preview version (v2.3.0.M4):
    Insert picture description here
  • Now that v2.3.0.RELEASE has been released, you can learn and use this feature with confidence. First, list the basic knowledge points to ensure that the preparation is OK;

Knowledge points

The following is the basic knowledge required to master the probe technology, which is also the main content of this article:

  1. kubernetes' survival probe livenessProbe ;
  2. kubernetes' readinessProbe ;
  3. SpringBoot的actuator

Next, learn one by one. With this accumulation of knowledge, we can better read official information and develop probes suitable for our business scenarios;

kubernetes' survival probe livenessProbe

  1. The probe of kubernetes involves a lot of content, here only the parts related to SpringBoot are mentioned;
  2. kubelet uses the liveness probe livenessProbe to know when to restart the container;
  3. The figure below is an example of survival probe on kubernetes official website. Several key parameters have been explained in detail:
    Insert picture description here
  4. It can be seen that if our SpringBoot application is released to the kubernetes environment, as long as the application is still healthy, the address corresponding to the livenessProbe must be able to respond with a return code of 200-400;

kubernetes' readinessProbe

  1. Sometimes, the application may temporarily fail to provide communication services. For example, an application may need to load a large data or configuration file when it starts, or it may rely on waiting for external services after it starts. In this case, neither want to kill the application nor send a request to it. Kubernetes provides readiness detectors to detect and mitigate these situations. The Pod where the container is located reports information that is not yet ready, and does not accept traffic through Kubernetes Service.
  2. The configuration of the ready probe is similar to that of the survival probe, the only difference is that the readinessProbe field is used instead of the livenessProbe field;
  3. To put it simply, k8s considers a container with a normal ready probe to provide services to the outside world, and the corresponding request will also be scheduled to the container;

SpringBoot的actuator

  1. Simply put, the actuator is used to help users monitor and operate the SprinBoot application. These monitoring and operations can be achieved through http requests, as shown in the figure below. The http://localhost:8080/actuator/health address returns the health status of the application :
    Insert picture description here
  2. The following are the commonly used actuator addresses. Different information can be obtained by visiting different addresses:
    Insert picture description here
  3. In the SpringBoot-2.3 version, the actuator has two new addresses: /actuator/health/liveness and /actuator/health/readiness . The former is used as a survival probe for kubernetes, and the latter is used as a ready probe for kubernetes ;

Voiceover: Is this the only thing about SpringBoot's probe technology?

  1. After reading this article, you may find it dull: The so-called container probe feature is so simple. Two new actuator addresses are reserved for kubernetes' survival and ready probes. As long as these two addresses respond normally, kubernetes will determine the container. normal;
  2. Most of the time, there is nothing wrong with the above conclusions. The recommended configuration given by SpringBoot is as follows, we just need to copy it:
    Insert picture description here
  3. Calm down and think carefully. Three problems seem to be unsolved:
  • First of all, SpringBoot provides two actuator items for kubernetes, but what about SringBoot applications that are not deployed in kubernetes? Should I expose these two service addresses if I don’t need them?

  • Second, when did the ready probe start to return a 200 return code? During the application startup phase, the business service may take a while to work normally. If the ready probe returns 200 in advance, then k8s thinks that the container can work normally. At this time, dispatching external requests will not respond normally, so find out that it is ready The state change logic of the probe is very important;

  • Finally, and the most important point: In some scenarios, such as external dependency service exceptions, local global exceptions, etc., the business does not want to provide services to the outside world. After the problem is solved, the business can provide services to the outside world. If we can do it ourselves Write the return code of the code control ready probe to control whether kubernetes dispatches external requests to this container. This is a very practical function!

Still need to go deeper

In the face of the above three questions, do you feel emotional: The seemingly simple container probe technology requires more knowledge if you want to use it well. In the next article , let’s work hard together, from knowledge coverage to practical exercises. Master this practical technology;

Welcome to my GitHub

Welcome to follow my public account: programmer Xin Chen

Insert picture description here

Guess you like

Origin blog.csdn.net/boling_cavalry/article/details/106605264