4-3 startupProbe, livenessProbe, readinessProbe探针对pod监测

三种探针

针对运行中的容器,kubelet 可以选择是否执行以下三种探针,以及如何针对探测结果作出反应:

startupProbe
指示容器中的应用是否已经启动。如果提供了启动探针,则所有其他探针都会被 禁用,直到此探针成功为止。如果启动探测失败,kubelet 将杀死容器,而容器依其 重启策略进行重启。
如果容器没有提供启动探测,则默认状态为 Success。

livenessProbe
指示容器是否正在运行。如果存活态探测失败,则 kubelet 会杀死容器, 并且容器将根据其重启策略决定未来。
如果容器不提供存活探针, 则默认状态为 Success。

readinessProbe
指示容器是否准备好为请求提供服务。如果就绪态探测失败, 端点控制器将从与 Pod 匹配的所有服务的端点列表中删除该 Pod 的 IP 地址。 初始延迟之前的就绪态的状态值默认为 Failure。
如果容器不提供就绪态探针,则默认状态为 Success。


部署探针

创建一个nginx Deployment,包含三种探针:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myserver-myapp-frontend-deployment
  namespace: myserver
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myserver-myapp-frontend-label
  template:
    metadata:
      labels:
        app: myserver-myapp-frontend-label
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: myserver-myapp-frontend-label
        image: nginx:1.20.2
        ports:
        - containerPort: 80
        startupProbe:
          httpGet:
            path: /index.html
            port: 80
          initialDelaySeconds: 5 #首次检测延迟5s
          failureThreshold: 3 #从成功转为失败的次数
          periodSeconds: 3 #探测间隔周期3s
        readinessProbe:
          httpGet:
            path: /index.html
            port: 80
          initialDelaySeconds: 5 #首次检测延迟5s
          periodSeconds: 3 #探测间隔周期3s
          timeoutSeconds: 5 #检测超时时间5s
          successThreshold: 1 #从失败转为成功的次数
          failureThreshold: 3 #从成功转为失败的次数
        livenessProbe:
          httpGet:
            path: /index.html
            port: 80
          initialDelaySeconds: 5 #首次检测延迟5s
          periodSeconds: 3 #探测间隔周期3s
          timeoutSeconds: 5 #检测超时时间5s
          successThreshold: 1 #从失败转为成功的次数
          failureThreshold: 3 #从成功转为失败的次数

---
apiVersion: v1
kind: Service
metadata:
  name: myserver-myapp-frontend-service
  namespace: myserver
spec:
  ports:
  - name: http
    port: 80
    targetPort: 80
    nodePort: 30080
    protocol: TCP
  type: NodePort
  selector:
    app: myserver-myapp-frontend-label

查看Pod中容器三种探针的配置情况:

kubectl describe pod myserver-myapp-frontend-deployment-556f9595c5-6sbsw -n myserver 
...
    Liveness:       http-get http://:80/index.html delay=5s timeout=5s period=3s #success=1 #failure=3
    Readiness:      http-get http://:80/index.html delay=5s timeout=5s period=3s #success=1 #failure=3
    Startup:        http-get http://:80/index.html delay=5s timeout=1s period=3s #success=1 #failure=3
...


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值