五 pod钩子 pod:pod hook和优雅的关闭nginx pod( 二 )


[root@k8scloude1 pod]# vim pod5.yaml #preStop处理函数指定在容器关闭之前执行"/bin/sh","-c","/usr/sbin/nginx -s quit"[root@k8scloude1 pod]# cat pod5.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: pod5name: pod5spec:terminationGracePeriodSeconds: 600containers:- image: nginxcommand: ["sh","-c","date > /tmp/aa.txt ; sleep 10000"]imagePullPolicy: IfNotPresentname: n1resources: {}lifecycle:postStart:exec:command: ["/bin/sh","-c","date >> /tmp/bb.txt"]preStop:exec:command: ["/bin/sh","-c","/usr/sbin/nginx -s quit"]dnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}[root@k8scloude1 pod]# kubectl apply -f pod5.yamlpod/pod5 created[root@k8scloude1 pod]# kubectl get podNAMEREADYSTATUSRESTARTSAGEpod51/1Running05s[root@k8scloude1 pod]# kubectl delete pod pod5pod "pod5" deleted^C[root@k8scloude1 pod]# kubectl delete pod pod5 --forcewarning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.pod "pod5" force deleted【五 pod钩子 pod:pod hook和优雅的关闭nginx pod】

推荐阅读