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 probe

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use the Kubernetes probe, 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 go to know it!

1. Basic introduction

When we run the application on K8s, we are more concerned about whether the application is running properly, but if we only check the running status of the application, it is difficult to tell whether the application is running; because in some cases, the normal operation of the container does not represent the health of the application, so we can use the probe provided by Kubernetes.

Use a probe to determine whether the application running in the container is running properly. Official document

There are three types of probes for Kubernetes:

Ready probe (Readiness Probe): determines whether the container is ready, and if not, the container will be not ready.

Survival probe (Liveness Probe): determine whether the application in the container is normal. If not, K8s will restart the container.

Start probe (Startup Probe): determine whether the application in the container has been started (the ready probe and survival probe will not be executed until the start probe is judged to be successful)

Probe mode:

Exec: determines the status code returned when the command exits by executing the specified command in the container. A value of 0 indicates normal.

HttpGet: send a GET request to the IP address, port and URL path of the container. If the status code of the response is between 200 and 399, it is normal.

TcpSocket: check the TCP of the container's IP address and specified port. If the port is open, it is normal.

Configuration items:

InitialDelaySeconds: start the probe check after waiting for the end of the time we define

PeriodSeconds: the interval between probes

TimeoutSeconds: the timeout of the probe, when it exceeds our defined time, will be considered a failure

SuccessThreshold: the minimum number of consecutive successes of the probe

FailureThreshold: the minimum number of consecutive failures of the probe

Below, we use different probe methods for these three probes, mainly in order to give you a brief introduction, not a fixed writing method; at the same time, these three probes can be used together; as is more common, the ready probe and the survival probe are used together (the startup probe is added after the K8s 1.6 version).

2. Introduction to the use of K8s probe 1) ready probe: [root@k8s-master01 ~] # vim tomcat-service.yamlapiVersion: v1kind: Podmetadata: tomcat-servicespec: containers:-name: tomcat-service image: tomcat:8.5.32 ports:-containerPort: 8080 readinessProbe: failureThreshold: 3 tcpSocket: port: 8080 initialDelaySeconds: 20 periodSeconds: 3 successThreshold: 1 timeoutSeconds: 2 [root@k8s-master01 ~] # kubectl create-f tomcat-service.yaml

We can view Pod's information through describe.

[root@k8s-master01 ~] # kubectl describe pod tomcat-service

2) Survival probe: [root@k8s-master01 ~] # vim tomcat-web-server.yamlapiVersion: v1kind: Podmetadata: name: tomcat-web-serverspec: containers:-name: tomcat-web-server image: tomcat:8.5.32 ports:-containerPort: 8080 livenessProbe: failureThreshold: 3 httpGet: path: / port: 8080 scheme: HTTP # you can use HTTP or HTTPS initialDelaySeconds: 20 periodSeconds: 3 successThreshold: 1 timeoutSeconds: 2 [root@k8s-master01 ~] # kubectl create-f tomcat-web-server.yaml

The above restart is because the container will be closed when the survival probe or startup probe is judged to be unsuccessful, and the container restart strategy will be involved later.

The default restart policy for the container is Always (that is, when the container exits, the container to be exited is restarted)

3) start probe: [root@k8s-master01 ~] # vim tomcat-async-service.yamlapiVersion: v1kind: Podmetadata: name: tomcat-async-servicespec: containers:-name: tomcat-async-service image: tomcat:8.5.32 ports:-containerPort: 8080 startupProbe: failureThreshold: 3 exec: command: ['/ bin/sh','-c' 'echo Hello World'] initialDelaySeconds: 20 periodSeconds: 3 successThreshold: 1 timeoutSeconds: 2 [root@k8s-master01 ~] # kubectl create-f tomcat-async-service.yaml

The above is all the content of this article "how to use Kubernetes probe". 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

Development

Wechat

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

12
Report