容器系列-09liveness存活性探测实验步骤
# vi liveness-exec.yaml
# kubectl apply -f liveness-exec.yaml
# kubectl get pods
# kubectl describe pods liveness-exec
# kubectl get pods
# kubectl exec -it liveness-exec -- /bin/sh
# kubectl get pods
# kubectl get pods
# kubectl logs liveness-exec
---演示
[root@xianchaomaster1 liveness]# vi liveness-exec.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec
labels:
app: liveness
spec:
containers:
- name: liveness
image: busybox
args: #创建测试探针探测的文件
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
livenessProbe:
initialDelaySeconds: 10 #延迟检测时间
periodSeconds: 5 #检测时间间隔
exec:
command:
- cat
- /tmp/healthy
~
[root@xianchaomaster1 liveness]# kubectl apply -f liveness-exec.yaml
pod/liveness-exec created
[root@xianchaomaster1 liveness]# kubectl get pods
NAME READY STATUS RESTARTS AGE
liveness-exec 0/1 ContainerCreating 0 6s
myapp-pod 1/1 Running 1 89m
nginx-7f466444dc-dnbz6 1/1 Running 3 3d7h
nginx-7f466444dc-mxgc8 1/1 Running 3 3d7h
nginx-test-75c685fdb7-dphvw 1/1 Running 1 28h
nginx-test-75c685fdb7-rvg8z 1/1 Running 1 28h
[root@xianchaomaster1 liveness]# kubectl describe pods liveness-exec
Name: liveness-exec
Namespace: default
Priority: 0
Node: xianchaonode1/192.168.126.181
Start Time: Mon, 03 Oct 2022 16:47:26 +0800
Labels: app=liveness
Annotations: cni.projectcalico.org/podIP: 10.244.121.43/32
cni.projectcalico.org/podIPs: 10.244.121.43/32
Status: Running
IP: 10.244.121.43
IPs:
IP: 10.244.121.43
Containers:
liveness:
Container ID: docker://838c306cb50a720b7667f27b92a3e9fb5cdcef7c61fbcd64b712a872c4e2b8bc
Image: busybox
Image ID: docker-pullable://busybox@sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
Port: <none>
Host Port: <none>
Args:
/bin/sh
-c
touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
State: Running
Started: Mon, 03 Oct 2022 16:47:43 +0800
Ready: True
Restart Count: 0
Liveness: exec [cat /tmp/healthy] delay=10s timeout=1s period=5s #success=1 #failure=3
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-w7znj (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-w7znj:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-w7znj
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 56s default-scheduler Successfully assigned default/liveness-exec to xianchaonode1
Normal Pulling 55s kubelet Pulling image "busybox"
Normal Pulled 39s kubelet Successfully pulled image "busybox" in 15.865741256s
Normal Created 39s kubelet Created container liveness
Normal Started 39s kubelet Started container liveness
Warning Unhealthy 1s (x2 over 6s) kubelet Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory
You have new mail in /var/spool/mail/root
[root@xianchaomaster1 liveness]# kubectl get pods
NAME READY STATUS RESTARTS AGE
liveness-exec 1/1 Running 0 93s
myapp-pod 1/1 Running 1 91m
nginx-7f466444dc-dnbz6 1/1 Running 3 3d7h
nginx-7f466444dc-mxgc8 1/1 Running 3 3d7h
nginx-test-75c685fdb7-dphvw 1/1 Running 1 28h
nginx-test-75c685fdb7-rvg8z 1/1 Running 1 28h
[root@xianchaomaster1 liveness]# kubectl get pods
NAME READY STATUS RESTARTS AGE
liveness-exec 1/1 Running 1 2m14s
myapp-pod 1/1 Running 1 91m
nginx-7f466444dc-dnbz6 1/1 Running 3 3d7h
nginx-7f466444dc-mxgc8 1/1 Running 3 3d7h
nginx-test-75c685fdb7-dphvw 1/1 Running 1 28h
nginx-test-75c685fdb7-rvg8z 1/1 Running 1 28h
You have new mail in /var/spool/mail/root
[root@xianchaomaster1 liveness]# kubectl exec -it liveness-exec -- /bin/sh
/ # exit
You have new mail in /var/spool/mail/root
[root@xianchaomaster1 liveness]# kubectl get pods
NAME READY STATUS RESTARTS AGE
liveness-exec 1/1 Running 2 4m5s
myapp-pod 1/1 Running 1 93m
nginx-7f466444dc-dnbz6 1/1 Running 3 3d7h
nginx-7f466444dc-mxgc8 1/1 Running 3 3d7h
nginx-test-75c685fdb7-dphvw 1/1 Running 1 29h
nginx-test-75c685fdb7-rvg8z 1/1 Running 1 29h
[root@xianchaomaster1 liveness]# kubectl get pods
NAME READY STATUS RESTARTS AGE
liveness-exec 1/1 Running 3 4m55s
myapp-pod 1/1 Running 1 94m
nginx-7f466444dc-dnbz6 1/1 Running 3 3d7h
nginx-7f466444dc-mxgc8 1/1 Running 3 3d7h
nginx-test-75c685fdb7-dphvw 1/1 Running 1 29h
nginx-test-75c685fdb7-rvg8z 1/1 Running 1 29h
[root@xianchaomaster1 liveness]# kubectl logs liveness-exec
You have new mail in /var/spool/mail/root
[root@xianchaomaster1 liveness]#
标签:09liveness,容器,exec,root,liveness,存活,Running,nginx,kubectl
From: https://blog.csdn.net/king01299/article/details/142484044