[root@k8s-master01 k8s-test]# cat livenessProbe-httpget.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-httpget-pod
namespace: default
spec:
containers:
- name: liveness-httpget-container
image: kone.com/library/nginx
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
livenessProbe:
httpGet:
port: http
path: /index.html
initialDelaySeconds: 1
periodSeconds: 3
timeoutSeconds: 10
[root@k8s-master01 k8s-test]#
創建kubectl create -f livenessProbe-httpget.yaml
查看此時重啓次數爲0
[root@k8s-master01 k8s-test]# kubectl get pod
NAME READY STATUS RESTARTS AGE
liveness-httpget-pod 1/1 Running 0 4m31s
進入容器刪除/usr/share/nginx/html/index.htm
kubectl exec -it liveness-httpget-pod -- rm -f /usr/share/nginx/html/index.html
然後看容器的重啓次數爲1
[root@k8s-master01 k8s-test]# kubectl get pod -w
NAME READY STATUS RESTARTS AGE
liveness-httpget-pod 1/1 Running 1 7m25s