ZBLOG

How to restart the entire pod if the probe in one container returns false in kubernetes?

To restart the entire pod if the probe in one container returns false in Kubernetes, you can use a liveness or readiness probe with a failure threshold and period.

First, specify the liveness or readiness probe in the pod definition for each container that requires it. The probe should check the health of the container’s application and return success (HTTP 200-399) if it is healthy, or failure (HTTP 400-599) if it is not.

Next, set the failureThreshold and periodSeconds properties in the pod spec to define how many consecutive failures are allowed before considering the container unhealthy and triggering a restart.

For example:

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - name: app-container
      image: my-app-image
      livenessProbe:
        httpGet:
          path: /healthz
          port: 8080
        initialDelaySeconds: 5
        periodSeconds: 10
        failureThreshold: 3

    - name: sidecar-container
      image: my-sidecar-image

  # Restart policy specifies what to do when a container fails.
  restartPolicy: Always

In this example, we have set failureThreshold to three consecutive failures within a periodSeconds of ten seconds for our livenessProbe. This means that if our app has been failing its health checks for more than thirty seconds straight, Kubernetes will trigger an automatic restart of all containers within that pod.

The restartPolicy specifies what action to take if any of these containers fail. In this case, we’ve set it to ‘Always’, which ensures that Kubernetes will always attempt to restart failed containers indefinitely until they come back up again successfully.

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=4709

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?