理解操作事件
Kubernetes在容器创建之后就会马上发送postStart事件,但是并没法保证一定会 这么做,它会在容器入口被调用之前调用postStart操作,因为postStart的操作跟容器的操作是异步的,而且Kubernetes控制台会锁住容器直至postStart完成,因此容器只有在 postStart操作完成之后才会被设置成为RUNNING状态。
Kubernetes在容器结束之前发送preStop事件,并会在preStop操作完成之前一直锁住容器 状态,除非Pod的终止时间过期了。
定义预启动和预结束事件操作
apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
containers:
- name: lifecycle-demo-container
image: nginx
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
preStop:
exec:
command: ["/usr/sbin/nginx","-s","quit"]
网友评论