首页
首页
文章目录
  1. 简介
  2. 思维导图
  3. HTTP检查
  4. TCP检查
  5. EXEC执行命令检查
  6. 扩展

k8s pod健康检查的三种方法

简介

这几天在弄一个新项目,之前一直使用了http的健康检查,一直没有使用过tcp端口健康检查,所以就有了今天这篇文章。

思维导图

kubernetes 健康检查的用法与作用

HTTP检查

例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
livenessProbe:
httpGet:
path: /hosws
port: 8080
scheme: HTTP
# 容器启动后多久开始检查
initialDelaySeconds: 60
# 检测频率(秒)
periodSeconds: 30
# 超时时间
timeoutSeconds: 20
# 成功后等待
successThreshold: 1
# 失败多少次后执行下一步操作
failureThreshold: 5
readinessProbe:
httpGet:
path: /hosws
port: 8080
scheme: HTTP
initialDelaySeconds: 30
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3

TCP检查

例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 8088
livenessProbe:
failureThreshold: 5
initialDelaySeconds: 15
periodSeconds: 20
successThreshold: 1
tcpSocket:
port: 8088

EXEC执行命令检查

例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-exec
spec:
containers:
- name: liveness
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
image: gcr.io/google_containers/busybox
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5

这个我没用过,所以只能把官方文档的例子弄过来了

扩展

可以使用命名的ContainerPort作为HTTP或TCP liveness检查:
例:

1
2
3
4
5
6
7
8
9
ports:
- name: hosws-port
containerPort: 8080
hostPort: 8080

livenessProbe:
httpGet:
path: /hosws
port: hosws-port

以上
End!

支持一下
扫一扫,我会更有动力更新
  • 微信扫一扫
  • 支付宝扫一扫