kubernetes第五天
1.容器的健康检查Probe(探针)之readinessProbe就绪探针
1.exec方式检查
#通过rc资源创建了三个pod,然后使用services资源,对外提供三个pod的容器的访问入口。
apiVersion: v1
kind: ReplicationController
metadata:name: web-rc-readlineprobe
spec:replicas: 3selector:name: lxczuoyong: webtemplate:metadata:labels:name: lxczuoyong: webspec:zuoyong: webzuoyong: webcontainers:- name: nginximage: harbor.lxcedu.com/base-img/nginx:1.14.2command:- /bin/sh- -c- "touch /tmp/healthy; sleep 5; rm -f /tmp/healthy; sleep 60"#容器的就绪性检查,如果执行command命令成功则,标记为未就绪状态readinessProbe:exec:command:- cat- /tmp/healthyfailureThreshold: 3initialDelaySeconds: 15periodSeconds: 1successThreshold: 1timeoutSeconds: 1
---
apiVersion: v1
kind: Service
metadata:name: web-readinessprobenamespace: default
spec:selector:name: lxczuoyong: webtype: ClusterIPports:- port: 80targetPort: 80protocol: TCP
readinessProbe探针,如果检查不符合条件,pod的状态会变为未就绪,如图READY为0/1
通过查询ep和svc也可以看出三个pod处于未就绪状态,所以也不会加入web-readinessprobe中,所以ep资源就为空,kubectl describe ep web-readinessprobe可以看到三个节点都为未就绪状态。
2.httpGet方式检查
把exec检查方法的无关command删除,再把里面exec换成下面代码就变成httpGet检查
httpGet:# 指定访问的端口号port: 80# 检测指定的访问路径path: /index.html
启动之后发现pod的容器16秒到17秒状态由未就绪变为就绪,说明:未检查时容器处于未就绪状态。
删除容器的index.html文件,
kubectl exec web-rc-readlineprobe-httpget-hncm4 -- rm /usr/share/nginx/html/index.html
发现对应的pods的容器处于未就绪状态。