当前位置:网站首页>Kubernetes 三打探针及探针方式
Kubernetes 三打探针及探针方式
2022-07-03 10:43:00 【Xinyi7777】
一、探针背景介绍
1、编排工具运行时,虽说pod挂掉会在控制器的调度下会重启,出现pod重启的时候,但是pod状态是running,无法真实的反应当时pod健康状态,我们可以通过Kubernetes的探针监控到pod的实时状态。
二、Kubernetes三种探针类型
启动探针(Startup Probe):判断容器内的应用是否启动完成(在启动探针判断成功前,就绪探针和存活探针将不会执行)
就绪探针(Readiness Probe):判断容器是否已经就绪,若未就绪,容器将会处于未就绪,未就绪的容器,不会进行流量的调度。
存活探针(Liveness Probe):判断容器内的应用程序是否正常,若不正常,K8s 将会重新重启容器。
三、探针的三种方式
exec:通过在容器内执行指定命令,来判断命令退出时返回的状态码,如果为 0 表示正常。
httpGet:通过对容器的 IP 地址、端口和 URL 路径来发送 GET 请求;如果响应的状态码在 200 ~ 399 间,表示正常。
tcpSocket:通过对容器的 IP 地址和指定端口,进行 TCP 检查,如果端口打开,表示正常。
四、配置项
initialDelaySeconds:等待我们定义的时间 结束后便开始探针检查;
periodSeconds:探针的 间隔时间;
timeoutSeconds:探针的 超时时间,当超过我们定义的时间后,便会被视为失败;
successThreshold:探针的 最小连续成功数量;
failureThreshold:探针的 最小连续失败数量;
下面我们分别对这三种探针使用了不同的探针方式,主要是为了方便给大家做一个简单的介绍,并不是固定写法;同时,这三种探针是可以配合使用的;像一般比较常见的便是 就绪探针和存活探针配合使用(启动探针是在 K8s 1.6 版本后增加的
五、探针使用介绍
1)启动探针
apiVersion: v1
kind: Pod
metadata:
name: nginx-start-up
namespace: probe
spec:
containers:
- name: nginx-start-up
image: nginx:latest
ports:
- containerPort: 80
startupProbe:
failureThreshold: 3 #失败三次算探针失败
exec:
command: ['/bin/sh','-c','echo Hello World']
initialDelaySeconds: 20 #延迟20s后进行第一次探针
periodSeconds: 3 #间隔3s进行一次探针
successThreshold: 1 #成功一次算探针ok
timeoutSeconds: 2 #超时2s算失败一次
2)就绪探针
apiVersion: v1
kind: Pod
metadata:
name: nginx-ready
namespace: probe
labels:
app: nginx-ready #验证就绪探针的关键参数
spec:
containers:
- name: nginx-ready
image: nginx:latest
ports:
- containerPort: 80
readinessProbe:
failureThreshold: 3
tcpSocket:
port: 80
initialDelaySeconds: 20
periodSeconds: 3
successThreshold: 1
timeoutSeconds: 2
端口检测正常:
写一个nodeport类型进行流量验证
apiVersion: v1
kind: Service
metadata:
name: ready-nodeport
labels:
name: ready-nodeport
namespace: probe
spec:
type: NodePort
ports:
- port: 88
protocol: TCP
targetPort: 80
nodePort: 30880
selector:
app: nginx-ready
模拟流量结果是ok的
现在修改下就绪探针tcpSocket检测方式的端口为81模拟下探针失败,流量会不会走到该pod
显示81端口不通,ready状态为0,但pod是running的,请求一下结果如下,流量打入失败。就绪探针失败,是不会给该pod打入流量的。
3)存活探针
apiVersion: v1
kind: Pod
metadata:
name: nginx-live
namespace: probe
labels:
app: nginx-live
spec:
containers:
- name: nginx-live
image: nginx:latest
ports:
- containerPort: 80
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
scheme: HTTP
initialDelaySeconds: 20
periodSeconds: 3
successThreshold: 1
timeoutSeconds: 2
生成一个nodeport类型service
apiVersion: v1
kind: Service
metadata:
name: live-nodeport
labels:
name: live-nodeport
namespace: probe
spec:
type: NodePort
ports:
- port: 89
protocol: TCP
targetPort: 80
nodePort: 30810
selector:
app: nginx-live
curl进行ip端口校验
修改httpget中port参数值为81,模拟存活探针失败,探针失败,会让pod进行重启。
六、探针恢复
修改探针探测端口正确,重新加载yaml文件,流量正常。
边栏推荐
- PHP基础
- How to clean up v$rman_ backup_ job_ Details view reports error ora-02030
- Stm32hal library upgrades firmware based on flash analog U disk (detailed explanation)
- Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power
- This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
- Abandon the Internet after 00: don't want to enter a big factory after graduation, but go to the most fashionable Web3
- How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
- PHP server interacts with redis with a large number of close_ Wait analysis
- Understand go language context in one article
- LeetCode 46:全排列
猜你喜欢
Summary of interview questions (2) IO model, set, NiO principle, cache penetration, breakdown avalanche
抓包整理外篇fiddler———— 会话栏与过滤器[二]
DS90UB949
行业唯一!法大大电子合同上榜36氪硬核科技企业
基于I2C协议的驱动开发
PHP server interacts with redis with a large number of close_ Wait analysis
银泰百货点燃城市“夜经济”
Driver development based on I2C protocol
AMS Series 1 - AMS startup process
DS90UB949
随机推荐
Machine learning 3.2 decision tree model learning notes (to be supplemented)
AMS series - application startup process
Oracle 11g single machine cold standby database
Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
One hot code
高精度室内定位技术,在智慧工厂安全管理的应用
面試題總結(2) IO模型,集合,NIO 原理,緩存穿透,擊穿雪崩
After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.
Web安全总结
Struct function & function pointer
Program process management tool -go Supervisor
项目管理精华读书笔记(七)
POI excel cell wrap
Reading notes: heart like Bodhi, Cao Dewang
The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities
DS90UB949
如何成为一名高级数字 IC 设计工程师(1-3)Verilog 编码语法篇:Verilog 行为级、寄存器传输级、门级(抽象级别)
用了这么久线程池,你真的知道如何合理配置线程数吗?
Google Earth engine (GEE) -- when we use the front and back images to make up for the interpolation effect, what if there is no effect?