pod生命周期:

状态:pending 挂起

没有节点满足条件

running 运行

Failed

sucess

unkonwn

pod生命周期中的重要行为:

初始化容器

容器探测:liveness probe  探测容器是否活着 探测容器 存活性探针

readindess probe 探测容器中主程序是否正常提供服务 就绪性探针

restartPolicy:容器重启策略

Always,OnFailure,Never,Default to always

pod终止过程:发送指令给容器并有等待机制

查看liveness, readindess

kubectl explain pods.spec.containers

探针类型有三种:探测容器

ExecAction:

TCPSocketAction:套接字探针

HTTPGetAction:

liveness Probe探测情况

kubectl explain pods.spec.containers.livenessProbe

例如

kubectl explain pods.spec.containers.livenessProbe.exec

liveness Probe探针类型:三种只用其中一种

exec <Object>

tcpSocket          <Object>

httpGet    <Object>

附加属性

failureThreshold       <integer> 探测几次失败,才认为失败

periodSeconds <integer>   探测间隔时间 单位秒

timeoutSeconds       <integer> 每次探测超时时间响应

initialDelaySeconds <integer>  容器初始化后延迟的探测时间,容器第一次探测时间 默认容器一启动就开始探测

readinessProbe就绪行探测的属性与livenessProbe一样

kubectl explain pods.spec.containers.readinessProbe

livenessProbe实例:

exec<Object>

kubectl explain pods.spec.containers.livenessProbe.exec

实例:

vim  leveness-exec.yaml

apiVersion: v1

kind: Pod

metadata:

name: liveness-exec-pod

namespace: default

spec:

containers:

- name: liveness-exec-container

image: busybox:latest

imagePullPolicy: IfNotPresent

command: ["/bin/sh","-c","touch /tmp/healthy;sleep 30;rm -f /tmp/healthy;sleep 3600"] 容器初始化命令

livenessProbe:

exec:   exec探针 执行

command: ["test","-e","/tmp/healthy"]  探测命令 返回true false 返回false的话restartPolicy容器重启策略执行 restart

initialDelaySeconds: 2 容器初始化后2秒探测

periodSeconds: 3  探针返回true 间隔3秒再探测

kubectl create -f leveness-exec.yaml

kubectl get pods –w

kubectl describe pods liveness-exec-pod

livenessProbe

tcpSocket探针

kubectl explain pods.spec.containers.livenessProbe.tcpSocket

livenessProbe

httpGet探针

kubectl explain pods.spec.containers.livenessProbe.httpGet

实例:

cp leveness-exec.yaml liveness-httpdget.yaml

vim liveness-httpdget.yaml

apiVersion: v1

kind: Pod

metadata:

name: liveness-httpget-pod

namespace: default

spec:

containers:

- name: liveness-httpget-container

image: ikubernetes/myapp:v1

imagePullPolicy: IfNotPresent

ports:

- name: http

containerPort: 80

livenessProbe:

httpGet:  探针

port: http  port的name

path: /index.html  请求的网页 网页请求不到,restartPolicy重启策略执行restart,重启之后 容器文件会重置

initialDelaySeconds: 1 容器初始化1秒后探测

periodSeconds: 3 间隔3秒探测

kubectl create -f liveness-httpdget.yaml

kubectl get pods –w

kubectl describe pods liveness-httpget-pod

查看Liveness:结果

实验过程:

kubectl exec -it liveness-httpget-pod -- /bin/sh   进入容器

rm -rf /usr/share/nginx/html/index.html

kubectl describe pods liveness-httpget-pod  显示 restart count

就绪性探测实例:

cp liveness-httpdget.yaml readiness-httpget.yaml

vim readiness-httpget.yaml

apiVersion: v1

kind: Pod

metadata:

name: readiness-httpget-pod

namespace: default

spec:

containers:

- name: readiness-httpget-container

image: ikubernetes/myapp:v1

imagePullPolicy: IfNotPresent

ports:

- name: http

containerPort: 80

readinessProbe:

httpGet:

port: http

path: /index.html 能够访问就会显示就绪 ready 1,访问不到就会显示不就绪 ready为0

initialDelaySeconds: 1

periodSeconds: 3

kubectl create -f readiness-httpget.yaml

kubectl get pods

实验过程

kubectl exec -it readiness-httpget-pod -- /bin/sh

rm -rf /usr/share/nginx/html/index.html

kubectl get pods

kubectl get pods 此时显示ready状态为0

kubectl exec -it readiness-httpget-pod -- /bin/sh

touch   /usr/share/nginx/html/index.html

kubectl get pods  此时ready为1  因为已经能够探测到了

kubectl describe pods readiness-httpget-pod  查看Readiness

容器启动后勾子,结束前勾子

kubectl explain pods.spec.containers.lifecycle

postStart <Object>

kubectl explain pods.spec.containers.lifecycle.postStart

实例:

vim poststart-pod.yaml

apiVersion: v1

kind: Pod

metadata:

name: poststart-pod

namespace: default

spec:

containers:

- name: busybox-httpd

image: busybox:latest

imagePullPolicy: IfNotPresent

lifecycle:

postStart:

exec:

command: ["/bin/sh","-c","mkdir -p /data/web/html;echo Home_Page>> /data/web/html/index.html"] 容器初始化后执行

command: ["/bin/sh",”-c”,”sleep 3600”] 容器启动 时执行  既容器初始化前就已经执行 先执行

kubectl create  -f  poststart-pod.yaml

kubectl get pods

登录检查勾子执行的结果

kubectl exec -it poststart-pod -- /bin/sh

ls /data/web/html/

cat  /data/web/html/index.html

preStop    <Object>

kubectl explain pods.spec.containers.lifecycle.preStop

注释:/bin/httpd  -f  -h /data/web/html

在前台执行 指定家目录

k8sd之pod生命周期的更多相关文章

  1. Kubernetes1.3:POD生命周期管理

    转:http://blog.csdn.net/horsefoot/article/details/52324830 (一)  核心概念 Pod是kubernetes中的核心概念,kubernetes对 ...

  2. Pod生命周期和健康检查

    Pod生命周期和健康检查 Pod的生命周期涵盖了前面所说的PostStart 和 PreStop在内 Pod phase Pod的status定义在 PodStatus对象中,其中有一个phase字段 ...

  3. Kubernetes Pod 生命周期

    一. Pod Hook Kubernetes 为我们提供了生命周期钩子,就是我们所说的Pod Hook,Pod Hook是由kubelet发起的,当容器中的进程启动前或者容器中的进程终止之前运行.这是 ...

  4. 2.k8s.Pod生命周期,健康检查

    #Pod生命周期,健康检查 pod创建过程 Init容器 就绪探测 存活探测 生命周期钩子 #Pod创建过程 master节点:kubectl -> kube-api -> kubenle ...

  5. k8s学习-pod生命周期

    4.2.pod生命周期 创建一个pod的时候过程如下: 1.容器环境初始化: 2.pause执行网络.容器卷等初始化工作: 3.所有的InitC按顺序执行,每个InitC执行完后才能执行下一个,且必须 ...

  6. 容器编排系统之Pod生命周期、健康/就绪状态探测以及资源限制

    前文我们了解了在k8s上的资源标签.标签选择器以及资源注解相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/14141080.html:今天我们来聊下k8 ...

  7. 【三】Kubernetes学习笔记-Pod 生命周期与 Init C 介绍

    一.容器生命周期 Init C(初始化容器)只是用于 Pod 初始化的,不会一直随着 Pod 生命周期存在,Init C 在初始化完成之后就会死亡. 一个 Pod 可以有多个 Init C,也可以不需 ...

  8. pod生命周期

    Pod生命周期 我们一般将pod对象从创建至终这段时间范围成为pod的生命周期,它主要包含以下的过程: pod创建过程 运行初始化容器(init container)过程 运行主容器(main con ...

  9. k8s的pod生命周期

    pod的生命周期: 1.init container 2.main contianer (1) post start hook :容器启动后做什么操作(可以命令查看kubectl explain po ...

  10. Pod 生命周期和重启策略

    Pod 在整个生命周期中被系统定义为各种状态,熟悉 Pod 的各种状态对于理解如何设置 Pod 的调度策略.重启策略是很有必要的. Pod 的状态 状态值 描述 Pending API Server ...

随机推荐

  1. 【.NET】调用本地 Deepseek 模型

    本篇咱们来聊一聊怎么在 .NET 代码中使用本地部署的 Deepseek 语言模型.大伙伴们不必要紧张,很简单的,你不需要学习新知识,只要你知道 .NET 如何访问 HTTP 和 JSON 的序列化相 ...

  2. zabbix - [03] 安装部署

    参考:https://www.yuque.com/fenghuo-tbnd9/ffmkvs zabbix6要求操作系统为Centos8,所以一开始安装部署的时候发现少了zabbix-server-my ...

  3. VMware虚拟机上安装Kali Linux详细教程

    1.Kali Linux简介 Kali Linux是一个基于Debian的开源Linux发行版,集成了精心挑选的渗透测试和安全审计的工具,供渗透测试和安全设计人员使用,面向各种信息安全任务:如渗透测试 ...

  4. 【自荐】Catime v1.0.4 一款贼好用的计时器

    Github: https://github.com/vladelaina/Catime 仅1.3MB!!!!! 特点 极简设计: 透明界面.点击穿透.可调大小和位置.多语言支持 丰富字体: 47种字 ...

  5. 学习高可靠Redis分布式锁实现思路

    一.分布式锁的必要性 在单体应用时代,我们使用ReentrantLock或synchronized就能解决线程安全问题.但当系统拆分为分布式架构后(目前大多数公司应该不会只是单体应用了),跨进程的共享 ...

  6. NumPy学习11

    今天学习了NumPy线性代数 21, NumPy线性代数 numpy_test11.py : import numpy as np ''' 21, NumPy线性代数 NumPy 提供了 numpy. ...

  7. 在Linux中查看分区表的4种方法

    作为Linux管理员,我们需要一次又一次地查看硬盘的分区表.这有助于我们通过为进一步分区腾出空间来重新组织旧驱动器,并在必要时为新驱动器创建空间.您可以在硬盘上创建不超过四个主分区,但可以在多个逻辑分 ...

  8. harbor

    一篇带你了解私有仓库 Harbor 的搭建 一.Harbor简介 虽然Docker官方提供了公共的镜像仓库,但是从安全和效率等方面考虑,部署我们私有环境内的Registry也是非常必要的. Harbo ...

  9. Oracle DB 关于CONNECT、RESOURCE 和DBA 角色权限

    授予角色的语法: grant <object/system privilege> to <role name>; 一般情况下,在新建数据库用户后,都会习惯性的给用户授权CONN ...

  10. 再谈MCP协议,看看 MCP 是如何重塑 AI 与外部数据源互动的能力?

    Techscribe Central 缩略图由 Techscribe Central 制作和编辑 MCP!!是不是一头雾水?我当时也是这个反应.我也是最近才听说它开始引发关注,然后我发现大多数人根本不 ...