1.探针的种类

livenessProbe: 健康状态检查,周期性检查服务是否存活,检查结果失败,将重启容器。

readinessProbe: 可用性检查,周期性检查服务是否可以,不可用将从service的endpoints中移除。

2.探针的检测方法:

  • exec : 执行一段命令,返回值为0 或非 0
  • httpGet: 检测某个http请求返回的状态码2xx 3xx正常,4xx,5xx错误
  • tcpSocket: 测试某个端口是否能够连接

3.1 liveness探针的exec使用

vi  nginx_pod_exec.yaml
apiVersion: v1
kind: Pod
metadata:
  name: exec
spec:
  containers:
    - name: nginx
      image: 10.0.0.11:5000/nginx:1.13
      ports:
        - containerPort: 80
      args:
        - /bin/sh
        - -c
        - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
      livenessProbe:
        exec:
          command:
            - cat
            - /tmp/healthy
        initialDelaySeconds: 5       #初始化检查,第一次检查在容器起来之后的第几秒
        periodSeconds: 5            #多长时间检查一次
        timeoutSeconds: 5            #超时时间
        successThreshold: 1            #成功几次代表是健康的
        failureThreshold: 1            #失败几次

3.2 liveness探针的httpGet使用

```vi nginx_pod_httpGet.yaml
apiVersion: v1
kind: Pod
metadata:
name: httpget
spec:
containers:
- name: nginx
image: 10.0.0.11:5000/nginx:1.13
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 3
periodSeconds: 3

###    3.3 liceness探针的tcpSocket使用

vi nginx_pod_tcpSocket.yaml
apiVersion: v1
kind: Pod
metadata:
name: tcpSocket
spec:
containers:
- name: nginx
image: 10.0.0.11:5000/nginx:1.13
ports:
- containerPort: 80
args:
- /bin/sh
- -c
- tail -f /etc/hosts
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 10
periodSeconds: 3

###    4.1readiness 探针的httpGet使用

vi nginx-rc-httpGet.yaml
iapiVersion: v1
kind: ReplicationController
metadata:
name: readiness
spec:
replicas: 2
selector:
app: readiness
template:
metadata:
labels:
app: readiness
spec:
containers:
- name: readiness
image: 10.0.0.11:5000/nginx:1.13
ports:
- containerPort: 80
readinessProbe:
httpGet:
path: /qiangge.html
port: 80
initialDelaySeconds: 3
periodSeconds: 3
```

12-23 19:14