Docker Kubernetes 健康检查html
提供Probe探测机制,有如下两种类型:nginx
Probe支持如下三种检查方法:docker
环境:vim
一、管理节点:建立yaml文件后端
vim check.yamlapi
apiVersion: v1 kind: Pod metadata: name: nginx-pod labels: app: nginx spec: containers: - name: nginx image: nginx:1.10 ports: - containerPort: 80 livenessProbe: httpGet: path: /index.html port: 80
# api版本 apiVersion: v1 # 指定建立资源对象 kind: Pod # 源数据、能够写name,命名空间,对象标签 metadata: # 服务名称 name: nginx-pod # 标签 labels: # 标签名 app: nginx # 容器资源信息 spec: # 容器管理 containers: # 容器名称 - name: nginx # 容器镜像 image: nginx:1.10 # 端口管理 ports: # 指定暴露端口 - containerPort: 80 # 健康检查模式(httpGet、exec、tcpSocket) livenessProbe: # 选择健康检查类型 httpGet: # 选择检查文件 path: /index.html # 选择检查暴露端口 port: 80
二、管理节点:建立Podapp
kubectl create -f check.yaml
命令:kubectl describe pods nginx-pod # 探测端口为80,探测文件名index.html,timeout超市时间为一秒,period每10秒探测一次 Liveness: http-get http://:80/index.html delay=0s timeout=1s period=10s #success=1 #failure=3
语法格式tcp
# 语法格式 apiVersion: v1 kind: Pod metadata: labels: test: liveness name: liveness-exec spec: containers: - name: liveness image: k8s.gcr.io/busybox 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
一、经过官方实例测试健康检查ide
apiVersion: v1 kind: Pod metadata: labels: test: liveness name: liveness-exec spec: containers: - name: liveness image: busybox 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
二、执行测试
kubectl create -f pod4.yaml
三、查看测试
kubectl get pods
通过一段时间检查重启
四、查看事件
kubectl describe pod liveness-exec
.... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 5m8s default-scheduler Successfully assigned default/liveness-exec to 192.168.1.110 Normal Pulled 2m35s (x3 over 5m7s) kubelet, 192.168.1.110 Successfully pulled image "busybox" Normal Created 2m35s (x3 over 5m6s) kubelet, 192.168.1.110 Created container Normal Started 2m34s (x3 over 5m6s) kubelet, 192.168.1.110 Started container Warning Unhealthy 112s (x9 over 4m32s) kubelet, 192.168.1.110 Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory Normal Pulling 81s (x4 over 5m7s) kubelet, 192.168.1.110 pulling image "busybox" Normal Killing 6s (x4 over 3m51s) kubelet, 192.168.1.110 Killing container with id docker://liveness:Container failed liveness probe.. Container will be killed and recreated.