livenessProbe 用来检测容器是否存活。
readinessProbe 用来检测服务是否可用(就绪),
另外还有 startupProbe 用来探测服务启动。(用在启动时间比较长的情况,启动成功后才交给livenessProbe)
ExeAction 在容器内执行命令,返回码为0表示成功
apiVersion: v1
kind: Pod
metadata:
name: test-liveness-probe1
spec:
containers:
- name: test-liveness-probe1
image: busybox
resources:
limits:
memory: "8Mi"
cpu: "500m"
command: ['/bin/sh','-c','echo ok > /tmp/health;sleep 10; rm -rf /tmp/health; sleep 600']
livenessProbe:
exec:
command:
- cat
- /tmp/health
initialDelaySeconds: 15
timeoutSeconds: 3 #命令超时时间,1.20之前无效
periodSeconds: 5 #探测间隔
failureThreshold: 3 # 重试几次表示失败
tcpSocket 通过端口测试TCP连接,能够建立连接表示成功
apiVersion: v1
kind: Pod
metadata:
name: test-liveness-probe1
spec:
containers:
- name: test-liveness-probe1
image: busybox
resources:
limits:
memory: "8Mi"
cpu: "500m"
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 15
timeoutSeconds: 1 #探测超时时间,默认1
periodSeconds: 5 #循环间隔
failureThreshold: 3 # 连续探测几次失败认为失败,默认3,最小1
Http 请求测试,返回的代码在200-400之间表示成功
apiVersion: v1
kind: Pod
metadata:
name: test-liveness-probe1
spec:
containers:
- name: test-liveness-probe1
image: busybox
resources:
limits:
memory: "8Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: Custom-Header
value: vvv
initialDelaySeconds: 15
timeoutSeconds: 3 #探测超时时间
periodSeconds: 5 #循环间隔
failureThreshold: 3 # 连续探测几次失败认为失败
readinessGates 这个没看懂怎么用通过外部Controller控制pods是否可用。
了解 工作生活心情记忆 的更多信息
订阅后即可通过电子邮件收到最新文章。