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

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

时间:2024-09-24 10:49:58浏览次数:10  
标签: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

相关文章

  • 如何使用Docker进入容器并运行命令
    在Docker的日常管理和应用开发过程中,经常会遇到需要与容器内部进行交互的情况。无论是调试应用程序还是检查服务状态,能够有效地进入容器内部执行命令都是非常必要的。本文将详细介绍如何通过Docker命令行工具进入一个正在运行的容器,并在其中执行各种命令。Docker简介Docker是......
  • 用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......
  • 20年架构师用一文带你彻底搞懂SpringBoot嵌入式Web容器原理
    ContainerLess理念微服务把应用和它所依赖的组件包、配置文件及附带的运行脚本打包成一个单一、独立、可执行的jar包文件。在实现Web服务器时,几乎不需要任何配置就可以启动Tomcat。你只需要使用java-jar命令就可以让Tomcat成为SpringBoot的一个自包含的可运行组件和单元。同时,这......
  • 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......
  • C++容器list底层迭代器的实现逻辑~list相关函数模拟实现
    目录1.两个基本的结构体搭建2.实现push_back函数3.关于list现状的分析(对于我们如何实现这个迭代器很重要)3.1和string,vector的比较3.2对于list的分析3.3总结4.迭代器类的封装5.list容器里面其他函数的实现6.个人总结7.代码附录1.两个基本的结构体搭建首先就是我......
  • 鸿蒙开发-Swiper(轮播图容器组件)
    Swiper组件提供滑动轮播显示的能力。Swiper本身是一个容器组件,当设置了多个子组件后,可以对这些子组件进行轮播显示。通常,在一些应用首页显示推荐的内容时,需要用到轮播显示的能力。针对复杂页面场景,可以使用Swiper组件的预加载机制,利用主线程的空闲时间来提前构建和布局绘制......