Kubernetes-健康状态检查
目录
-
readinessprobe
说明:健康状态对POD的服务(端口TCP,HTTP协议)进行检查,保证APP高可用 -
健康检查--重启POD
1.livenessProbe: 健康检查失败,重启pod解决问题
failureThreshold # 失败最大次数 3
initialDelaySeconds # POD启动之后, 延时多少才进行检测
periodSeconds 5 # 多少秒钟检查一次
successThreshold 2 # 连续成功多次检查 认为健康检查成功
timeoutSeconds 10 #会话超时时间
- POD启用livenessProbe,检查POD健康状态
trnuser@k8s:~/pod/dc$ cat dc1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: dc2
name: dc2
spec:
replicas: 2
selector:
matchLabels:
app: dc2
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: dc2
spec:
containers:
- image: nginx
name: nginx
livenessProbe:
httpGet:
path: /index.html
port: 80
scheme: HTTP
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 400m
status: {}
- 添加参数
trnuser@k8s:~/pod/dc$ cat dc-liveness.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: dc2
name: dc2
spec:
replicas: 2
selector:
matchLabels:
app: dc2
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: dc2
spec:
containers:
- image: nginx
name: nginx
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
httpGet:
path: /index.html
port: 80
scheme: HTTP
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 400m
status: {}
- 健康检查--不重启POD,从SVC中删除
- readinessprobe
会从SVC中删除,但不会重建POD,若replica==2,会变为单点
trnuser@k8s:~/pod/dc$ cat dc-liveness.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: dc2
name: dc2
spec:
replicas: 2
selector:
matchLabels:
app: dc2
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: dc2
spec:
containers:
- image: nginx
name: nginx
readinessProbe: # POD应答策略
failureThreshold: 3
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
httpGet:
path: /index.html
port: 80
scheme: HTTP
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 400m
status: {}