【问题标题】:Does Kubelet repeatedly restart the pod by default?Kubelet 默认会重复重启 pod 吗?
【发布时间】:2020-07-24 09:51:09
【问题描述】:

我正在开始使用 Kubernetes,我正在尝试了解有关活性探测的更多信息。

一些文档和文章告诉failureThreshold 的默认值是 3 倍。而当你不指定 failureThreshold 时,Kubernetes 会在重启容器之前进行 3 次探测。

我的问题是,kubelet 重启 pod 容器多少次?

这是一个示例 livenessprobe-execaction.yaml:

apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: k8s.gcr.io/busybox
    args: # command to be executed when the container starts
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600 # during first 30 seconds there will be a file and cat will return success, when removed, a failure
    livenessProbe:
      exec:
        command: # in the first probe there will be a file within 30 seconds, and no errors
                 # and after 35 seconds a nex probe is done but the file is gone, and error will show up and machine will be restarted
                 # several restarts should happen or restarts only 3 times?
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5 # kubelet waits 5 seconds before first probe
      periodSeconds: 5 # kubelet checks every 5 seconds
      #failureThreshold: 3 is the default number of times, after the 3rd liveness probe the container is restarted? forever?

创建 pod 后:

$ kubectl apply -f livenessprobe-execaction.yaml

还有手表:

$ kubectl get pod liveness-exec --watch

输出是:

    NAME            READY   STATUS    RESTARTS   AGE
    liveness-exec   1/1     Running   0          4s
    liveness-exec   1/1     Running   1          75s
    liveness-exec   1/1     Running   2          2m29s
    liveness-exec   1/1     Running   3          3m44s
    liveness-exec   1/1     Running   4          5m
    liveness-exec   1/1     Running   5          6m14s
    liveness-exec   0/1     CrashLoopBackOff   5          7m29s
    liveness-exec   1/1     Running            6          8m57s
    liveness-exec   1/1     Running            7          10m
    liveness-exec   0/1     CrashLoopBackOff   7          11m
    liveness-exec   1/1     Running            8          16m
    liveness-exec   1/1     Running            9          17m
    liveness-exec   0/1     CrashLoopBackOff   9          18m

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    这取决于 PodSpec 中的restartPolicy

    PodSpec 有一个 restartPolicy 字段,其可能值 AlwaysOnFailureNever。默认值为AlwaysrestartPolicy 适用于 Pod 中的所有容器。 restartPolicy 仅指同一节点上的 kubelet 重新启动容器。由 kubelet 重启的已退出容器会以指数回退延迟(10 秒、20 秒、40 秒……)重启,上限为 5 分钟,并在成功执行 10 分钟后重置

    【讨论】:

      【解决方案2】:

      感谢您的回复。我已经看到了一些类似的答案,但这并不能很好地解释一个 pod 将重新启动多少次。答案是,从今天开始,它将在默认模式“始终”下永远重启。

      似乎没有办法设置最大重启次数。

      您要么重新启动“总是”、“失败”或“从不”。在总是和失败模式下,5 分钟只是重试启动容器之间的最长等待时间。

      “从不”不会重新启动容器。

      因此,目前还没有选项可以帮助我们设置最大重试次数。

      引用 Dan Wahlin 的话,它有关于这个主题的课程:

      首先,5 分钟是重新启动之间的最大上限时间。 如果你再次运行它,你会发现它肯定开始变慢 重新启动很多(见下文)并将达到仅 每 5 分钟尝试一次。它坚持这个数字,除非容器 是健康的(在这种情况下它会重置)。

      就最大重启次数而言(这是您的问题 真的关于我现在意识到),看起来他们还在努力 从我在 github 网站上可以看出的那个功能。我不正常 必须处理这种情况(通常是集群管理员) 但如果我遇到其他任何事情,我会告诉你的。

      https://github.com/kubernetes/kubernetes/issues/49466 https://github.com/kubernetes/kubernetes/pull/79334

      看起来这是将解决它的特定拉取请求:

      https://github.com/kubernetes/kubernetes/pull/79334/files/db71ebf0ec9bc04c48542059ccd46a34a2abcc16#diff-e281c21e93f01ecc8cf12e4ff535b3e5

      【讨论】:

        猜你喜欢
        • 2018-03-06
        • 2020-05-22
        • 2012-04-11
        • 2019-12-21
        • 1970-01-01
        • 2017-10-21
        • 1970-01-01
        相关资源
        最近更新 更多