首页 > 其他分享 >容器系列-09liveness存活性探测实验步骤

容器系列-09liveness存活性探测实验步骤

时间:2024-09-24 10:49:58浏览次数:13  
标签:09liveness 容器 exec root liveness 存活 Running nginx kubectl

容器系列-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

相关文章

  • 用Podman搭建LAMP开发环境的容器(五) -- 端口转发
    上接:用Podman搭建LAMP开发环境的容器(四)–使用VSCode今天接着折腾前几天的VSCode配置。虽然现在看着好像是差不多了,也可以在VSCode上面编写代码了。但是还有一个很大的问题:容器中Apache服务的端口并没有映射到本地,所以现在用浏览器不能访问我写的页面,也不能访问phpMyAdmi......
  • 简单得实现IOC容器控制反转和依赖注入,并分析原理
    目录IOC容器依赖反转/注入AnnotationConfigApplicationContextspring容器启动类(相当于spring容器)完整简单理解代码参考文章链接:https://blog.csdn.net/heyl163_/article/details/132515809IOC容器Component注解:标记是否要创建bean,传入bean的名称@Target(Elem......
  • 滚雪球学SpringCloud[9.1讲]:Docker与容器化详解
    全文目录:前言9.1Docker与容器化Docker的基本概念与SpringBoot应用的容器化1.Docker的核心概念2.将SpringBoot应用容器化DockerCompose与微服务编排1.DockerCompose的核心概念2.使用DockerCompose编排微服务使用Kubernetes部署SpringCloud应用1.Kubernetes......
  • Dockerfile全面指南:从基础到进阶,掌握容器化构建的核心工具
    目录Dockerfile全面指南:从基础到进阶,掌握容器化构建的核心工具引言一、什么是Dockerfile二、Dockerfile的基本结构三、Dockerfile的常见配置项1、多阶段构建(Multi-stageBuilds)2、缓存优化3、合并RUN命令四、Dockerfile使用须知五、一个完整的Dockerfile实......
  • 计算机低能儿从0刷leetcode | 11.盛最多水的容器
    题目:11.盛最多水的容器解答:不想暴力遍历,于是让右端点j从最右侧开始遍历,每次寻找离j最远、且高度不小于height[j]的左端点i,结果发现错误,比如[1,2]的情况。于是又打补丁,按同样思路左端点i从0开始遍历,每次寻找离i最远、且高度不小于height[i]的右端点j,结果正确,然而时间复杂度......
  • Docker进入容器运行命令实例讲解
    Docker进入容器运行命令实例讲解在Docker中,要进入正在运行的容器并执行命令,主要使用dockerexec命令。这个命令允许你在运行中的容器内执行一个新的命令,这对于调试、运行附加的进程或在容器内部进行管理操作非常有用。基本语法dockerexec[OPTIONS]CONTAINERCOMMAND[ARG......