k8s-12-pod的健康检查
1.容器的重启策略always:默认的重启策略,当容器停止,会创建新的容器onFailure:容器异常退出,重启容器Never:当容器终止退出,从不重启容器2.健康策略livenessProbe:如果检查失败,根据pod的restartPolicy来操作readinessProbe:如果检查失败,kubernetes会把pod从service...
·
1.容器的重启策略
always:默认的重启策略,当容器停止,会创建新的容器 onFailure:容器异常退出,重启容器 Never:当容器终止退出,从不重启容器
2.健康策略
livenessProbe:如果检查失败,根据pod的restartPolicy来操作 readinessProbe:如果检查失败,kubernetes会把pod从service endpoint中删除
3. 健康检查的三种方式
httpGet: 发送http请求,返回状态200-400状态码为成功 exec:执行shell命令返回为0 表示成功 tcpSocket:发送TCP socket建立成功
4.测试
apiVersion: v1 kind: Pod metadata: name: nginx-pod labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 livenessProbe: httpGet: path: /index.html port: 80
5.观察
kubectl create -f nginx.yaml [root@k8s-master ~]# kubectl logs nginx-pod -f 172.17.52.1 - - [13/Oct/2018:09:55:57 +0000] "GET /index.html HTTP/1.1" 200 612 "-" "kube-probe/1.9" "-" 172.17.52.1 - - [13/Oct/2018:09:56:07 +0000] "GET /index.html HTTP/1.1" 200 612 "-" "kube-probe/1.9" "-" 172.17.52.1 - - [13/Oct/2018:09:56:17 +0000] "GET /index.html HTTP/1.1" 200 612 "-" "kube-probe/1.9" "-" 172.17.52.1 - - [13/Oct/2018:09:56:27 +0000] "GET /index.html HTTP/1.1" 200 612 "-" "kube-probe/1.9" "-" 172.17.52.1 - - [13/Oct/2018:09:56:37 +0000] "GET /index.html HTTP/1.1" 200 612 "-" "kube-probe/1.9" "-" 172.17.52.1 - - [13/Oct/2018:09:56:47 +0000] "GET /index.html HTTP/1.1" 200 612 "-" "kube-probe/1.9" "-" 172.17.52.1 - - [13/Oct/2018:09:56:57 +0000] "GET /index.html HTTP/1.1" 200 612 "-" "kube-probe/1.9" "-" [root@k8s-master ~]# kubectl describe pod nginx-pod Name: nginx-pod Namespace: default Node: 192.168.56.12/192.168.56.12 Start Time: Sat, 13 Oct 2018 17:55:44 +0800 Labels: app=nginx Annotations: <none> Status: Running IP: 172.17.52.2 Containers: nginx: Container ID: docker://c03454a77f363b4b3f7dc31091dd92bd234200cb1eb341f262b1573f874a0315 Image: nginx Image ID: docker-pullable://nginx@sha256:9ad0746d8f2ea6df3a17ba89eca40b48c47066dfab55a75e08e2b70fc80d929e Port: 80/TCP State: Running Started: Sat, 13 Oct 2018 17:55:51 +0800 Ready: True Restart Count: 0 Liveness: http-get http://:80/index.html delay=0s timeout=1s period=10s #success=1 #failure=3 ##############策略 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-jjkz6 (ro) Conditions: Type Status Initialized True Ready True PodScheduled True Volumes: default-token-jjkz6: Type: Secret (a volume populated by a Secret) SecretName: default-token-jjkz6 Optional: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 2m default-scheduler Successfully assigned nginx-pod to 192.168.56.12 Normal SuccessfulMountVolume 2m kubelet, 192.168.56.12 MountVolume.SetUp succeeded for volume "default-token-jjkz6" Normal Pulling 2m kubelet, 192.168.56.12 pulling image "nginx" Normal Pulled 2m kubelet, 192.168.56.12 Successfully pulled image "nginx" Normal Created 2m kubelet, 192.168.56.12 Created container Normal Started 2m kubelet, 192.168.56.12 Started container [root@k8s-master ~]# 上面可以看出健康检查的策略 以及频率
6.如果把nginx的默认的index.html删除会出现什么情况呢
删除了容器的index.html以后 容器健康检查 失败 然后根据默认的容器重启策略 新建立容器,restartPolicy可以自定义,新建的容器也是用最初的yaml建立的 而且是一个名字。如下是新建立的容器 index.html还是存在的
root@nginx-pod:/usr/share/nginx/html# ll bash: ll: command not found root@nginx-pod:/usr/share/nginx/html# ls -l total 8 -rw-r--r-- 1 root root 494 Oct 2 14:49 50x.html -rw-r--r-- 1 root root 612 Oct 2 14:49 index.html root@nginx-pod:/usr/share/nginx/html#
转载于:https://blog.51cto.com/wsxxsl/2299505
更多推荐
已为社区贡献466条内容
所有评论(0)