关于Liveness 探测和 Readiness 探测在使用中
2020-07-22 本文已影响0人
生活就是闹剧
实验目的
- 判断Liveness 探测 对副本数变化
- 判断Readiness 探测 对副本数变化
- 判断Readiness 探测 再次健康时是否从新加入svc
Liveness 实验
# cat centos.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: centos-test
name: centos-test
spec:
replicas: 5
selector:
matchLabels:
app: centos-test
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: centos-test
spec:
containers:
- image: centos:7
name: centos
args:
- tail
- -f
- /etc/hosts
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 60
periodSeconds: 3
# kubectl exec -it POD_NAME -- python -m SimpleHTTPServer 80
实验小结
副本数变化没有任何变化,pod名字也没有变化.
Readiness 实验
# cat centos.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: centos-test
name: centos-test
spec:
replicas: 5
selector:
matchLabels:
app: centos-test
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: centos-test
spec:
containers:
- image: centos:7
name: centos
args:
- tail
- -f
- /etc/hosts
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 60
periodSeconds: 3
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: centos-test
name: centos-svc
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: centos-test
type: NodePort
# kubectl exec -it POD_NAME -- python -m SimpleHTTPServer 80
实验小结
副本数变化没有任何变化,健康状态下ep可以挂载Pod IP
健康健康,不健康从ep摘除,健康从ep挂载
整体总结
- Liveness 探测 用于应用本身导致的错误重启可以快速解决
- Readiness 探测 用于自身是否可以正常接收流量,和非本身问题导致的错误,等待后端问题解决就可以恢复