在pod主动驱逐或者主动删除的过程中,如何实现应用的优雅的关闭,待pod处理完所有请求
apiVersion: apps/v1
kind: Deployment
metadata:
name: gracefulshutdown-app
spec:
replicas: 3
selector:
matchLabels:
app: gracefulshutdown-app
template:
metadata:
labels:
app: gracefulshutdown-app
spec:
containers:
- name: graceful-shutdown-test
image: gracefulshutdown-app:latest
ports:
- containerPort: 8080
lifecycle:
preStop:
exec:
command: ["sh", "-c", "sleep 10"] #set prestop hook
terminationGracePeriodSeconds: 45 # terminationGracePeriodSeconds
重点在于:
lifecycle:preStop
terminationGracePeriodSeconds
terminationGracePeriodSeconds默认是30s,所以优雅停pod时间为: terminationGracePeriodSeconds=preStop+应用停止需要的时间
原本时间轴:

配置对应应用、控制器后的时间轴:

浙公网安备 33010602011771号