k8s-Pod生命周期

我这个人很好相处,处不好你自己想想原因。

Pod生命周期

在这里插入图片描述

pod创建过程

  • 用户通过kubectl提交要创建的pod信息给apiserver
  • apiserver生成pod对象,将信息存储至etcd,返回确认信息给客户端
  • 其他组件使用watch机制来跟踪检查apiserver上的变动
  • scheduler发现有新的pod对象要创建,开始分配主机并将结果更新至apiserver
  • node节点上的kubelet发现有pod调度过来,启动docker,并将结果返回apiserver
  • apiserver将信息存储至etcd中

初始化容器

  • 主要进行一些主容器的前置工作。

主容器-钩子函数

  • exec命令 在容器内执行一次命令
#常见的一种执行方式
......
	lifecycle: 
		postStart:
        	exec:
        		command:
        		- cat:
        		- /tmp/healthy

主容器-容器探测

  • 用于检测容器中的应用实例是否正常工作
  • 存活性探针:检测应用实例是否处于正常运行状态,如果不是,就会重启
  • 就绪性探针:检测应用实例是否可以接收请求,如果不能,k8s不会转发流量
存活性探针决定是否重启容器,就绪性探针决定是否将流量转发给容器

探测方式:

#exec命令
......
	livenessProbe: 
    	exec:
    		command:
    		- cat:
    		- /tmp/healthy
kubectl explain pod.spec.containers.livenessProbe

FIELDS:
	#探针的三种探测方式
   exec <Object>
   tcpSocket    <Object>
   httpGet<Object>
 	 #连续探测失败多少次认为失败  
   failureThreshold
     Minimum consecutive failures for the probe to be considered failed after
     having succeeded. Defaults to 3. Minimum value is 1.
     #容器启动后多少秒执行第一次探测
   initialDelaySeconds  <integer>
     Number of seconds after the container has started before liveness probes
     are initiated. More info:
     #执行探测的频率
   periodSeconds        <integer>
     How often (in seconds) to perform the probe. Default to 10 seconds. Minimum
     value is 1.
     #连续探测成功多少次认为成功  
   successThreshold     <integer>
     Minimum consecutive successes for the probe to be considered successful
     after having failed. Defaults to 1. Must be 1 for liveness and startup.
     Minimum value is 1.
     #探测超时时间
   timeoutSeconds       <integer>
     Number of seconds after which the probe times out. Defaults to 1 second.
     Minimum value is 1. More info:

pod的终止过程

  • 用户向apiserver发送删除pod命令
  • 将pod标记为terminating状态
  • kubelet监控到pod对象变为terminating状态,启动pod的终止过程
  • service列表中删除该pod相关信息,外界不能再通过service访问到该pod
  • 如果当前pod定义了pre-stop钩子处理函数,在标记为terminating的时候同步启动该函数
  • pod对象中的容器收到停止信号
  • kubelet完成pod删除操作,此时对用户将不可见
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值