python - uwsgi master 优雅关机
问题描述
我正在运行 uwsgi+flask 应用程序,该应用程序作为 k8s pod 运行。
当我部署一个新的 pod(新版本)时,现有的 pod 会得到 SIGTERM。
这会导致 master在同一时刻停止接受新连接,这会导致问题,因为 LB 仍将请求传递给 pod(再持续几秒钟)。
我希望主人在停止接受新连接之前等待 30 秒(当获得 SIGTERM 时)但找不到方法,这可能吗?
我的 uwsgi.ini 文件:[uwsgi]
;https://uwsgi-docs.readthedocs.io/en/latest/HTTP.html
http = :8080
wsgi-file = main.py
callable = wsgi_application
processes = 2
enable-threads = true
master = true
reload-mercy = 30
worker-reload-mercy = 30
log-5xx = true
log-4xx = true
disable-logging = true
stats = 127.0.0.1:1717
stats-http = true
single-interpreter= true
;https://github.com/containous/traefik/issues/615
http-keepalive=true
add-header = Connection: Keep-Alive
解决方案
使用uwsgi似乎无法实现:
https://github.com/unbit/uwsgi/issues/1974
解决方案 - (如this kubernetes issue中所述):
https://github.com/kubernetes/contrib/issues/1140
就是使用prestop hook,比较难看但是有助于实现零停机:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
spec:
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
lifecycle:
preStop:
exec:
command: ["/bin/sleep","5"]
推荐阅读
- javascript - 如何根据javascript中未知数量的参数更改函数
- duplicates - 解码或 NVL,我试图避免重复
- python - 跨行的 Numpy 矩阵乘法不稳定性
- python - matplotlib 在 opencv 窗口后不显示图形
- angular - 如何使用 Angular 中的 chart.js 条形图在标签之后和数值之前显示符号
- java - 如何禁用休眠序列信息获取
- excel - VBA UserForm 使用带有数字的动态名称范围编辑条目
- java - 是否可以互相翻译 ServerHttpRequest 和 HttpServletRequest
- javascript - Leaftlet - 如果在地图边界之外,防止位置标记出现
- kotlin - 在 Kotlin 中合并地图列表