温馨提示  2024年 6月我们已经停止开发者板块文章内容更新,谢谢来访。存档数据
知识 2023-08-29 32 次阅读

怎样达成pod就绪性探测

    云计算

本篇文章为大家展示了怎样达成pod就绪性探测,内容长篇大论并且容易理解,绝对能使你眼前一亮,通过本文的详细介绍希望你能有所收获。

   当pod容器启动成功后还没有加载配置和数据,以及其它第三方脚本服务,在这过程中如有客户端发送请求会等待太久,响应较慢,这会大大影响客户的体验。所以呢,为了不让当pod启动成功后立即处理客户端请求,而是等待容器所有初使化工作完成后进入“就绪”状态。就绪性探测失败时不会杀死或重启容器,而是确保不会有客户端请求进入pod对像。就绪性探测支持三种方法exec,httpget和tcpsocket。

1.使用exec探测文件存在

[root@k8s01 yaml]# kubectl explain pods.spec.containers.readinessprobe

[root@k8s01 yaml]# vim execreadiness.yaml

apiversion: v1
kind: pod
metadata:
  labels:
    test: exec-readinessprobe
  name: readinessprobe
spec:
  containers:
  - name: exec-readinessprobe
    image: busybox:latest
    args: [/bin/sh,-c,touch /tmp/test.txt]
    readinessprobe:
      exec:
        command: [test,-e,/tmp/test.txt]    --探测文件是否存在,如果存在立即进入就绪性
      initialdelayseconds: 5     --pod初使化完成后使用command命令进行探测(5秒)
      periodseconds: 5    --探测周期5秒

[root@k8s01 yaml ]# kubectl apply -f execreadiness.yaml

pod/readinessprobe created

[root@k8s01 yaml ]#

上面的文章就是怎样达成pod就绪性探测,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。