應用高可用

應用高可用的一般原則

  • 使用 Service 和多副本 Pod 部署應用

  • 多副本通過反親和性避免單節點故障導致應用異常

  • 使用 PodDisruptionBudget 避免驅逐導致的應用不可用

  • 使用 preStopHook 和健康檢查探針保證服務平滑更新

優雅關閉

爲 Pod 配置 terminationGracePeriodSeconds,並通過 preStop 鉤子延遲關閉容器應用以避免 kubectl drain 等事件發生時導致的應用中斷:

restartPolicy: Always
terminationGracePeriodSeconds: 30
containers:
- image: nginx
  lifecycle:
    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",
        ]

詳細的原理可以參考下面這個系列文章

參考文檔

Last updated