当前位置:网站首页>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文件,流量正常。
边栏推荐
- Reading notes: heart like Bodhi, Cao Dewang
- AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
- 2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func mai
- CSRF
- MATLAB提取不规则txt文件中的数值数据(简单且实用)
- Leetcode 46: full arrangement
- Matlab extracts numerical data from irregular txt files (simple and practical)
- How to make others fear you
- After using the thread pool for so long, do you really know how to reasonably configure the number of threads?
- This article explains the complex relationship between MCU, arm, MCU, DSP, FPGA and embedded system
猜你喜欢

Gut | 香港中文大学于君组揭示吸烟改变肠道菌群并促进结直肠癌(不要吸烟)

Unity移动端游戏性能优化简谱之 画面表现与GPU压力的权衡

机器学习 3.2 决策树模型 学习笔记(待补)

Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation

Cadence background color setting

AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...

The world's most popular font editor FontCreator tool

2022 东北四省赛 VP记录/补题

FL Studio 20 unlimited trial fruit arranger Download

MATLAB extrait les données numériques d'un fichier txt irrégulier (simple et pratique)
随机推荐
C language log base zlog basic use
基于I2C协议的驱动开发
Encapsulation attempt of network request framework of retro + kotlin + MVVM
AMS series - application startup process
软考中级软件设计师该怎么备考
银泰百货点燃城市“夜经济”
Machine learning 3.2 decision tree model learning notes (to be supplemented)
C language utf8toutf16 (UTF-8 characters are converted to hexadecimal encoding)
多维度监控:智能监控的数据基础
FL Studio 20 unlimited trial fruit arranger Download
ORACLE进阶(一) 通过EXPDP IMPDP命令实现导dmp
Unique in the industry! Fada electronic contract is on the list of 36 krypton hard core technology enterprises
AI模型看看视频,就学会了玩《我的世界》:砍树、造箱子、制作石镐样样不差...
Based on MCU, how to realize OTA differential upgrade with zero code and no development?
[vtk] source code interpretation of vtkpolydatatoimagestencil
读书笔记:《心若菩提》 曹德旺
项目管理精华读书笔记(七)
Use typora to draw flow chart, sequence diagram, sequence diagram, Gantt chart, etc. for detailed explanation
Google Earth engine (GEE) - ghsl global population grid dataset 250 meter resolution
How to become a senior digital IC Design Engineer (1-4) Verilog coding syntax: expression