应用遵循 The Twelve-Factor App
使用 Service 和多副本 Pod 部署应用
多副本通过反亲和性避免单节点故障导致应用异常
使用 PodDisruptionBudget 避免驱逐导致的应用不可用
使用 preStopHook 和健康检查探针保证服务平滑更新
为 Pod 配置 terminationGracePeriodSeconds,并通过 preStop 钩子延迟关闭容器应用以避免 kubectl drain
等事件发生时导致的应用中断:
restartPolicy: AlwaysterminationGracePeriodSeconds: 30containers:- image: nginxlifecycle:preStop:exec:command: ["sh", "-c",# Introduce a delay to the shutdown sequence to wait for the# pod eviction event to propagate. Then, gracefully shutdown# nginx."sleep 5 && /usr/sbin/nginx -s quit",]
详细的原理可以参考下面这个系列文章