K8S哲学 - probe 探针

news/2024/9/25 9:30:49/

探针分类:

liveness probe

readiness probe

startup probe

  1. Liveness Probe:用于检查容器是否还在运行。如果 Liveness Probe 失败,Kubernetes 会杀死容器,然后根据你的重启策略来决定是否重新启动容器。常见的做法是使用与 Readiness Probe 相同的低成本 HTTP 端点,但是设置更高的 failureThreshold,这样可以确保在 Pod 被强制杀死之前,它会被观察到为 not-ready 一段时间。

  2. Readiness Probe:用于检查容器是否准备好接受流量。一个 Pod 被认为是 ready 的,当且仅当它的所有容器都是 ready 的。这个信号的一个用途是控制哪些 Pod 被用作 Service 的后端。当一个 Pod 不是 ready 的,它会从 Service 的负载均衡器中移除。

  3. Startup Probe:用于检查容器应用程序是否已经启动。如果配置了这样的探针,那么在它成功之前,Liveness Probe 和 Readiness Probe 不会开始,确保这些探针不会干扰应用程序的启动。这可以用于对慢启动的容器进行 Liveness 检查,避免它们在启动并运行之前被 kubelet 杀死。

探测方式

HTTPGetAction

TCPSocketAction

ExecAction

每种探针都可以使用以下三种方式之一进行检查:

  • HTTP GET:对容器的一个 HTTP 服务器发起一个 GET 请求。如果服务器返回的状态码在 200 到 399 之间,那么探针就是成功的。

  • TCP Socket:尝试打开容器的一个 TCP 端口。如果端口已经打开,那么探针就是成功的。

  • Exec:在容器中执行一个命令。如果命令返回 0,那么探针就是成功的。

 

ERROR: The Pod "app" is invalid: spec.containers[0].livenessProbe.successThreshold: Invalid value: 3: must be 1

对于 Liveness 探针,successThreshold 的值必须为 1。这是因为 Liveness 探针只需要一次成功的探测就能确定容器是存活的。所以,你需要将 successThreshold 的值改为 1。

apiVersion: v1
kind: Pod
metadata:name: 'app'labels: name: 'zs'age: '18'
spec:containers:- name: 'probe-po'image: nginx:1.14.2livenessProbe:httpGet:path: /index.htmlport: 80initialDelaySeconds: 5periodSeconds: 5timeoutSeconds: 5failureThreshold: 3successThreshold: 1

这时 如果将 index.html 改成 index1.html 

 livenessProbe 采用 tcpSocket

apiVersion: v1
kind: Pod
metadata:name: 'app'labels: name: 'zs'age: '18'
spec:containers:- name: 'probe-po'image: nginx:1.14.2livenessProbe:# httpGet:#   path: /index1.html#   port: 80# initialDelaySeconds: 5# periodSeconds: 5# timeoutSeconds: 5# failureThreshold: 3# successThreshold: 1tcpSocket:port: 80periodSeconds: 5successThreshold: 1failureThreshold: 3

livenessProbe 采用 exec

apiVersion: v1
kind: Pod
metadata:name: 'app'labels: name: 'zs'age: '18'
spec:containers:- name: 'probe-po'image: nginx:1.14.2livenessProbe:# httpGet:#   path: /index1.html#   port: 80# initialDelaySeconds: 5# periodSeconds: 5# timeoutSeconds: 5# failureThreshold: 3# successThreshold: 1# tcpSocket:#  port: 89# periodSeconds: 5# successThreshold: 1# failureThreshold: 3exec:command: ['cat', '/usr/share/nginx/html/index.html']# - cat# - /usr/share/nginx/html/index.htmlsuccessThreshold: 1failureThreshold: 3timeoutSeconds: 3periodSeconds: 3

改成 index1.html

配置 livenessProbe readinessProbe startupProbe

apiVersion: v1
kind: Pod
metadata:name: 'app'labels: name: 'zs'age: '18'
spec:containers:- name: 'probe-po'image: nginx:1.14.2livenessProbe:# httpGet:#   path: /index1.html#   port: 80# initialDelaySeconds: 5# periodSeconds: 5# timeoutSeconds: 5# failureThreshold: 3# successThreshold: 1# tcpSocket:#  port: 89# periodSeconds: 5# successThreshold: 1# failureThreshold: 3exec:command: ['cat', '/usr/share/nginx/html/index1.html']# - cat# - /usr/share/nginx/html/index.htmlsuccessThreshold: 1failureThreshold: 3timeoutSeconds: 3periodSeconds: 3readinessProbe: httpGet: path: /index.htmlport: 80failureThreshold: 3successThreshold: 1 timeoutSeconds: 3periodSeconds: 3startupProbe: httpGet:path: /index.htmlport: 80failureThreshold: 3successThreshold: 1timeoutSeconds: 3periodSeconds: 3

 


http://www.ppmy.cn/news/1427367.html

相关文章

iced 入门一

📕作者简介: 过去日记,致力于Java、GoLang,Rust等多种编程语言,热爱技术,喜欢游戏的博主。 📘相关专栏Rust初阶教程、go语言基础系列、spring教程等,大家有兴趣的可以看一看 📙Jav…

I2C,UART,SPI(STM32、51单片机)

目录 基本理论知识: 并行通信/串行通信: 异步通信/同步通信: 半双工通信/全双工通信: UART串口: I2C串口: SPI串口: I2C在单片机中的应用: 软件模拟: 51单片机:…

通往大厂之路:Solr面试题及参考答案100道题

目录 什么是Solr,它主要用来做什么? 解释Solr和Lucene的关系。 Solr有哪些主要特点?

[阅读笔记15][Orca]Progressive Learning from Complex Explanation Traces of GPT-4

接下来是微软的Orca这篇论文,23年6月挂到了arxiv上。 目前利用大模型输出来训练小模型的研究都是在模仿,它们倾向于学习大模型的风格而不是它们的推理过程,这导致这些小模型的质量不高。Orca是一个有13B参数的小模型,它可以学习到…

STM32学习和实践笔记(18):STM32的外部中断的配置

如上图,EXTI的0-15是分配给GPIO的16个引脚。 但是GPIO差不多每个端口都有16个引脚,具体是怎样分配的呢? 很简单,就是通过AFIO寄存器来选择和分配。 比如,EXTI0,可以分配给GPIOA0,GPIOB0...GP…

AI大模型日报#0420:开源模型击败GPT-4、西湖大学蛋白质通用大模型、GPT的七条经验

导读: 欢迎阅读《AI大模型日报》,内容基于Python爬虫和LLM自动生成。目前采用“文心一言”生成了每条资讯的摘要。 标题: 开源模型打败GPT-4!LLM竞技场最新战报,Cohere Command R上线 摘要: GPT-4在LLM竞技场被开源模型Cohere的…

【leetcode面试经典150题】64. 删除排序链表中的重复元素 II(C++)

【leetcode面试经典150题】专栏系列将为准备暑期实习生以及秋招的同学们提高在面试时的经典面试算法题的思路和想法。本专栏将以一题多解和精简算法思路为主,题解使用C语言。(若有使用其他语言的同学也可了解题解思路,本质上语法内容一致&…

Flutter 的 showDialog 和 showCupertinoDialog 有什么区别?

我将我的 App 里用的 Flutter 升级到了 3.19,没想到,以前我用 showDialog 和 AlertDialog 组合创建的二次确认框,变得无敌难看了,大幅度增加了整个框的圆角和里面默认按钮的圆角。不得已,我必须修改一下,以…