当前位置:网站首页>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文件,流量正常。
边栏推荐
- After setting up ADG, instance 2 cannot start ora-29760: instance_ number parameter not specified
- Linear table sequence table comprehensive application problem p18
- 2022 northeast four provinces match VP record / supplementary questions
- [OBS] configFile in ini format of OBS
- repo ~ 常用命令
- Incremental database backup - DB incr DB full
- MATLAB提取不規則txt文件中的數值數據(簡單且實用)
- Analysis of JMM memory model
- The manuscript will be revised for release tonight. But, still stuck here, maybe what you need is a paragraph.
- AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
猜你喜欢

多维度监控:智能监控的数据基础

How to get started embedded future development direction of embedded
![抓包整理外篇fiddler———— 会话栏与过滤器[二]](/img/04/e9cc027d753e7049f273d866eefdce.png)
抓包整理外篇fiddler———— 会话栏与过滤器[二]

Résumé des questions d'entrevue (2) Modèle io, ensemble, principe NiO, pénétration du cache, avalanche de rupture

Multi dimensional monitoring: the data base of intelligent monitoring

金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~

Event preview | the live broadcast industry "rolled in" to drive new data growth points with product power

软考中级软件设计师该怎么备考

Matlab extracts numerical data from irregular txt files (simple and practical)

Modular programming of single chip microcomputer
随机推荐
VPP three-layer network interconnection configuration
聊聊Flink框架中的状态管理机制
Driver development based on I2C protocol
AMS series - application startup process
MATLAB提取不規則txt文件中的數值數據(簡單且實用)
导师对帮助研究生顺利完成学业提出了20条劝告:第一,不要有度假休息的打算.....
Software testing weekly (issue 78): the more confident you are about the future, the more patient you are about the present.
How to become a senior digital IC Design Engineer (1-5) Verilog coding syntax: operand
How to make others fear you
Modular programming of single chip microcomputer
Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
Qt+VTK+OCCT读取IGES/STEP模型
Intel 13th generation core flagship exposure, single core 5.5ghz
Redis things
AOSP ~ NTP ( 网络时间协议 )
repo ~ 常用命令
Spl06-007 air pressure sensor (example of barometer)
FL Studio 20 unlimited trial fruit arranger Download
Phpcms prompt message page Jump to showmessage
Web安全总结