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 realize Pod Health check in kubernetes

2025-02-23 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 achieve Pod health examination in kubernetes, I believe 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!

One: preface

The health status of Pod can be checked by two types of probes: LivenessProbe and ReadinessProbe.

1.LivenessProbe probe: used to determine whether the container is alive. If the LivenessProbe probe detects that the container is unhealthy, kubelet will kill the container and handle it accordingly according to the container's restart policy. If a container does not contain a LivenessProbe probe, kubelet thinks that the LivenessProbe probe return value of the container is always "Success".

2.ReadinessProbe probe: used to determine whether the container has been started and can receive requests. If the ReadinessProbe probe detects a failure, the state of the Pod will be modified. Endpoint Controller removes Endpoint. Endpoint Controller from Service's Endpoint, including the Pod where the container is located.

Second: LivenessProbe implementation

1.ExecAction: execute a command inside the container. If the return code of the command is 0, the surface container is healthy.

ApiVersion: v1

Kind: Pod

Metadata:

Labels:

Test: liveness

Name: liveness-exec

Spec:

Containers:

-name:liveness

Image:busybox

Args:

-/ bin/sh

-- c

-echo ok > / tmp/health; sleep 10; rm-rf / tmp/health; sleep 600

LivenessProbe:

Exec:

Command:

-cat

-/ tmp/health

InitialDelaySeconds: 15

TimeoutSeconds: 1

Determine whether a container is working properly by executing the "cat / tmp/health" command. After the Pod runs, the / tmp/health file will be deleted 10 seconds after it is created, while the initial detection time (initialDelaySeconds) of the LivenessProbe health check is 15 seconds, and the detection result will be Fail, which will cause kubelet to kill the container and restart it.

2.TCPSocketAction: TCP check is performed through the IP address and port number of the container. If a TCP connection can be established, the container on the surface is healthy.

ApiVersion: v1

Kind: Pod

Metadata:

Name: pod-with-healthcheck

Spec:

Containers:

-name: nginx

Image: nginx

Ports:

-containerPort: 80

LivenessProbe:

TcpSocket:

Port: 80

InitialDelaySeconds: 30

TimeoutSeconds: 1

3. HTTPGetAction: call the HTTPGet method through the IP address, port number and path of the container. If the status code of the response is greater than or equal to 200 and less than 400, the container is considered to be in a healthy state.

ApiVersion: v1

Kind: Pod

Metadata:

Name: pod-with-healthcheck

Spec:

Containers:

-name: nginx

Image: nginx

Ports:

-containerPort: 80

LivenessProbe:

HttpGet:

Port: 80

Path: / _ status/healthz

InitialDelaySeconds: 30

TimeoutSeconds: 1

Kubelet sends HTTP requests to localhost:80/_status/healthz regularly to check the health of container applications.

Three: explanation

1.initialDelaySeconds: the waiting time for the first health check after starting the container (in s)

2.timeoutSeconds: the timeout for waiting for a response after a health check sends a request, in s. When a timeout occurs, kubelet will think that the container can no longer provide service and will restart the container.

The above is all the contents of the article "how to achieve Pod Health check in kubernetes". 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