Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Kubernetes Health check

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to use Kubernetes health examination, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Liveness Probes

Kubernetes health examination is divided into liveness and readiness probes. Liveness probes is used to detect whether your application is running. Normally, as soon as your program crashes, Kubernetes will see that the program has been terminated and restart it. But the purpose of liveness probes is to capture situations when the program has not been terminated, crashed or fallen into a deadlock. So a simple HTTP response can be satisfied.

Here is an example I used to use a health check for a Go application.

In configuration

The image above tells Kubernetes that the application is running. InitialDelaySeconds told Kubernetes to delay starting the health check after seeing pod start, and made it clear how many seconds it would be delayed. If your application needs some time to start, you can use this setting to help it. TimeoutSeconds tells Kubernetes how long to wait for a health check. For liveness probes, this time should not be too long, but in case there is an underload, you really need to give your application enough time to respond.

If the application never starts, or if there is a HTTP error code in response, then Kubernetes will restart pod. You'd better not do anything too cool in liveness probes, don't even think about it, because once the liveness probes function starts to fail, it will cause errors in your application.

Readiness Probes

Readiness Probes is very similar to liveness probes, except that the results of failure detection are different. Readiness Probes is used to check whether your application can serve communications. This is slightly different from liveness. For example, your application depends on the database and memcached. If both of the above are in good condition, provide communication for your application, and then you can say that both of them are "readiness" of your application.

If the readness probe of your application fails, the pod will be removed from the endpoints that make up the service. In this way, if there is no prepared pods, no traffic traffic will be sent to them through the Kubernetes service discovery mechanism. This state is very helpful when it comes to service's new pod startup; when expanding events, scrolling updates, and so on. Readiness probes confirms that pods is not communicating when pods is turned on, and that they are not communicating when they are waiting for service.

The definition of Readiness probe is the same as liveness probes. Readiness probes is defined as part of Deployment, such as this:

Do you want to check whether you can connect to your application's dependencies in your readiness probe? Taking our dependence on the database as an example, we want to check to see if we can connect to both.

This should look like this (shown in the following figure). I check the memcached and the database, and if one is not available, I will reply with a 503 response status.

More stable application

Liveness and Readiness probes are very helpful in increasing the stability of your application. They help to confirm whether the communication flows only to the instance prepared for it, as does self-healing when the application becomes unresponsive. They are what my colleagues call a better solution called "12 Fractured Apps". With proper health checks, you can configure your application in any order without worrying about correlation or complex entry point scripts. When the application is ready, they start service communication, so automatic scheduling and rolling updates run smoothly.

The above is all the contents of the article "how to use Kubernetes Health examination". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report