惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
美团技术团队
H
Hacker News: Front Page
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
The Exploit Database - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
About on SuperTechFans
F
Fortinet All Blogs
量子位
GbyAI
GbyAI
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
Forbes - Security
Forbes - Security
Help Net Security
Help Net Security
I
InfoQ
有赞技术团队
有赞技术团队
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
C
Check Point Blog
T
Troy Hunt's Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news
P
Proofpoint News Feed
Jina AI
Jina AI
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
雷峰网
雷峰网
博客园 - Franky
L
LangChain Blog
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
D
Docker
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - 茁壮的小草

join查询中索引建议 tomcat连接池的“bug” 连接池介绍 JDBC介绍 Hadoop完全分布式搭建 Apache Hadoop YARN 使用 kubebuilder 创建并部署 k8s-operator 单链表反转 单链表操作 如何在Kubernetes 里添加自定义的 API 对象(一) 搭建golang开发环境(1.14之后版本) 【源码】Redis命令处理过程 【源码】Redis exists命令bug分析 【源码】Redis Server启动过程 K8S中的Objects MAC 安装MySQL-python 公司里使用gitlab管理项目 vscode配置django开发环境最佳实战(mac) virtualenv最佳实战(windows)
K8S配置存活、就绪和启动探测器
茁壮的小草 · 2022-02-09 · via 博客园 - 茁壮的小草

如何给容器化部署业务配置合适的探针?

readinessprobe简介

readinessprobe,就绪探针,是k8s中的一个概念。当 readinessprobe 检查通过,表示服务就绪,可以接受流量。当 readinessprobe 检查不通过,表示服务没有就绪,不具备提供服务流量的能力。和我们使用的consul agent的对服务的探活是类似的。

可以使用这些字段精确的控制存活和就绪检测的行为:

  • initialDelaySeconds:容器启动后要等待多少秒后存活和就绪探测器才被初始化,默认是 0 秒,最小值是 0。
  • periodSeconds:执行探测的时间间隔(单位是秒)。默认是 10 秒。最小值是 1。
  • timeoutSeconds:探测的超时后等待多少秒。默认值是 1 秒。最小值是 1。
  • successThreshold:探测器在失败后,被视为成功的最小连续成功数。默认值是 1。 存活和启动探测的这个值必须是 1。最小值是 1。
  • failureThreshold:当探测失败时,Kubernetes 的重试次数。 存活探测情况下的放弃就意味着重新启动容器。 就绪探测情况下的放弃 Pod 会被打上未就绪的标签。默认值是 3。最小值是 1。

目前 readinessprobe 支持三种探测方式:

  • http
  • tcp
  • exec

这三种我们建议使用http方式,更加准确反应服务的健康状态。

http 探测 demo:

readinessProbe:                   #健康检查方式
  failureThreshold: 3             #检测失败3次表示未就绪
  httpGet:                        #请求方式
    path: /actuator/health        #请求路径,此处修改为自己真实的路径,demo是java sdk 提供的接口路径
    port: 8080                    #请求端口,此处修改成自己真实的http监听端口
    scheme: HTTP                  #请求协议
  periodSeconds: 10               #检测间隔
  successThreshold: 1             #检查成功为1次表示就绪
  timeoutSeconds: 1               #监测超时时间

tcp demo:

# 此处需要填写完整的readinessProbe
# 这里是tcp 方式的readinessProbe
readinessProbe:
  tcpSocket:
    port: 5666 // 此处注意修改成自己真实的rpc监听端口
  periodSeconds: 10
  successThreshold: 1
  failureThreshold: 3

最佳实践

对于探针的配置,有一定的最佳实践。

有以下几点:

  • ReadinessProbe 要反应业务的真实健康状况。如果有预热逻辑,预热后再让ReadinessProbe 通过检查。
  • LivenessProbe  要慎用,LivenessProbe 失败会重启 Pod,不要轻易使用,除非你了解后果并且明白为什么你需要它,参考 Liveness Probes are Dangerous 。
  • LivenessProbe 相对ReadinessProbe 条件要更宽松。
  • 如果配置LivenessProbe,注意设置合适的 initialDelaySeconds 值,建议180s或更长,具体根据自己业务启动情况配置。尤其java 应用。

线上配置可以参考如下规则:

readinessProbe:                   #健康检查方式
  failureThreshold: 3             #检测失败3次表示未就绪
  httpGet:                        #请求方式
    path: /actuator/health        #请求路径,此处修改为自己真实的路径,demo是java sdk 提供的接口路径
    port: 8080                    #请求端口,此处修改成自己真实的http监听端口
    scheme: HTTP                  #请求协议
  periodSeconds: 10               #检测间隔
  successThreshold: 1             #检查成功为1次表示就绪
  timeoutSeconds: 1               #监测超时时间
livenessProbe:
  initialDelaySeconds: 180        #健康检查方式
  failureThreshold: 3             #检测失败3次表示未存活
  httpGet:                        #请求方式
    path: /actuator/health        #请求路径,此处修改为自己真实的路径,demo是java sdk 提供的接口路径
    port: 8080                    #请求端口,此处修改成自己真实的http监听端口
    scheme: HTTP                  #请求协议
  periodSeconds: 60               #检测间隔
  successThreshold: 1             #检查成功为1次表示存活
  timeoutSeconds: 1               #监测超时时间

如何检查

readinessprobe通过之前,在ones看到实例的状态为HealthChecking的状态,如果长时间处于HealthChecking状态,需要在pod详情中查看是否有健康检查失败的事件,通常为:Readiness probe failed: xxx

举例:

Readiness probe failed: dial tcp 192.168.158.87:8080: connect: connection refused

参考:https://kubernetes.io/zh/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/