容器鉤子
容器鉤子分為post-start和pre-stop
post-start:容器啟動后執行的命令
pre-stop:容器關閉前執行的命令,可用于優雅關閉
#?分別定義兩個鉤子,啟動pod后更新index.html,關閉pod前正常關閉服務
vi post-pre.yaml
apiVersion: v1
kind: Pod
metadata:name: life-demo
spec:containers:- name: lifecycle-demo-containerimage: 172.16.80.140/nginx/nginx:1.26imagePullPolicy: IfNotPresentlifecycle:postStart:exec:command: ["/bin/sh", "-c","echo 'lifecycle post-start' > /usr/share/nginx/html/index.html"]preStop:exec:command:- "/bin/sh"- "-c"- "nginx -s stop"
# 上圖可以看出,nginx在啟動之前,就被post-start改寫了index.html文件