首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当库伯奈特准备就绪-探针返回假时会发生什么?要等多久?

当库伯奈特准备就绪-探针返回假时会发生什么?要等多久?
EN

Stack Overflow用户
提问于 2021-12-02 15:50:08
回答 1查看 1.2K关注 0票数 0

当Kubernetes readiness-probe返回false时会发生什么?在超时后库伯内特斯会重启那个吊舱吗?库伯奈特等了多久?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-12-02 16:02:00

就绪探测不重新启动吊舱/容器,就绪探测确定容器已准备好为通信服务。如果容器被探测,并被认为没有“就绪”,容器将被从端点移除,并且在它再次准备就绪之前,流量不会发送到它。

1

2

3个kubectl explain pod.spec.containers.readinessProbe

代码语言:javascript
复制
KIND:     Pod
VERSION:  v1

RESOURCE: readinessProbe <Object>

DESCRIPTION:
     Periodic probe of container service readiness. Container will be removed
     from service endpoints if the probe fails. Cannot be updated. More info:
     https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

     Probe describes a health check to be performed against a container to
     determine whether it is alive or ready to receive traffic.

FIELDS:
   exec <Object>
     One and only one of the following should be specified. Exec specifies the
     action to take.

   failureThreshold <integer>
     Minimum consecutive failures for the probe to be considered failed after
     having succeeded. Defaults to 3. Minimum value is 1.

   httpGet  <Object>
     HTTPGet specifies the http request to perform.

   initialDelaySeconds  <integer>
     Number of seconds after the container has started before liveness probes
     are initiated. More info:
     https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

   periodSeconds    <integer>
     How often (in seconds) to perform the probe. Default to 10 seconds. Minimum
     value is 1.

   successThreshold <integer>
     Minimum consecutive successes for the probe to be considered successful
     after having failed. Defaults to 1. Must be 1 for liveness and startup.
     Minimum value is 1.

   tcpSocket    <Object>
     TCPSocket specifies an action involving a TCP port. TCP hooks not yet
     supported

   timeoutSeconds   <integer>
     Number of seconds after which the probe times out. Defaults to 1 second.
     Minimum value is 1. More info:
     https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

让我们使用文档中的默认准备状态探针:

代码语言:javascript
复制
cat pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
    readinessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5

要执行探测,kubelet在目标容器中执行cat /tmp/healthy命令。如果命令成功,则返回0,容器就就绪,可以“服务”。如果命令只返回0以外的任何内容,容器就不健康。

由于这个文件从一开始就不存在于容器中,所以当容器启动时,它将非常不健康。

代码语言:javascript
复制
date && k get pods nginx
Thu  2 Dec 2021 19:08:43 AST
NAME    READY   STATUS    RESTARTS   AGE
nginx   0/1     Running   0          66s

现在,让exec进入它并创建文件,这样命令就成功了。

代码语言:javascript
复制
k exec -it nginx -- bash
root@nginx:/# touch /tmp/healthy
root@nginx:/# exit
exit

再次检查:

代码语言:javascript
复制
date && k get pods nginx
Thu  2 Dec 2021 19:09:26 AST
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          110s

再次移除:

代码语言:javascript
复制
k exec -it nginx -- bash
root@nginx:/# rm /tmp/healthy
root@nginx:/# exit
exit

检查:

代码语言:javascript
复制
date && k get pods nginx
Thu  2 Dec 2021 19:09:53 AST
NAME    READY   STATUS    RESTARTS   AGE
nginx   0/1     Running   0          2m17s
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70202542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档