From 932fb96179592ede5d90b5bbc22f067ef6677135 Mon Sep 17 00:00:00 2001 From: roc Date: Fri, 19 Apr 2024 15:45:54 +0800 Subject: [PATCH] update at 2024-04-19 15:45:54 --- codeblock/graceful/update-strategy.yaml | 36 +++++++++++++++++++ .../graceful-shutdown/update-strategy.md | 12 +++++++ content/best-practices/sidebars.ts | 1 + 3 files changed, 49 insertions(+) create mode 100644 codeblock/graceful/update-strategy.yaml create mode 100644 content/best-practices/graceful-shutdown/update-strategy.md diff --git a/codeblock/graceful/update-strategy.yaml b/codeblock/graceful/update-strategy.yaml new file mode 100644 index 0000000..cf7fa54 --- /dev/null +++ b/codeblock/graceful/update-strategy.yaml @@ -0,0 +1,36 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + strategy: + # highlight-start + type: RollingUpdate + rollingUpdate: # 单个串行升级,等新副本 ready 后才开始销毁旧副本 + maxUnavailable: 0 + maxSurge: 1 + # highlight-end + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:latest + startupProbe: + httpGet: + path: / + port: 80 + # highlight-next-line + successThreshold: 5 # 新副本启动时,连续探测成功多次后才交给 readinessProbe 探测 + readinessProbe: + httpGet: + path: / + port: 80 + # highlight-next-line + successThreshold: 1 # 运行过程中探测 1 次成功就认为 ready,可在抖动导致异常后快速恢复服务 diff --git a/content/best-practices/graceful-shutdown/update-strategy.md b/content/best-practices/graceful-shutdown/update-strategy.md new file mode 100644 index 0000000..9799d57 --- /dev/null +++ b/content/best-practices/graceful-shutdown/update-strategy.md @@ -0,0 +1,12 @@ +# 配置保守的更新策略 + +## 保守更新策略 + +如果对稳定性要求较高,可以设置比较保守的滚动更新策略: +1. 避免在滚动时可以正常处理请求的 Pod 数量减少导致部分请求因后端 Pod 处理不过来而异常。 +2. 减缓发版速度,避免新版应用引入难以发现的问题快速扩散,方便发现后及时回滚恢复。 +3. 新副本启动时,多给应用一些时间进行准备,避免某些应用虽然探测接口返回就绪,但实际处理能力还没跟上,过早转发请求过来可能导致异常。 + +## 配置示例 + + diff --git a/content/best-practices/sidebars.ts b/content/best-practices/sidebars.ts index 95eb6bb..db823c0 100644 --- a/content/best-practices/sidebars.ts +++ b/content/best-practices/sidebars.ts @@ -18,6 +18,7 @@ const sidebars: SidebarsConfig = { 'graceful-shutdown/why-cannot-receive-sigterm', 'graceful-shutdown/propagating-signals-in-shell', 'graceful-shutdown/use-prestop', + 'graceful-shutdown/update-strategy', 'graceful-shutdown/persistent-connection', 'graceful-shutdown/lb-to-pod-directly', ],