如何在 Python 脚本中重启 Kubernetes-Engine Pods

How to restart Kubernetes-Engine Pods in a Python script

我正在寻找一种方法来重新启动我的所有 pods 服务。他们应该一个接一个地重新启动,以便服务始终可用。当来自不同服务的 Python 脚本完成时,应该会重新启动。

我这样做是因为在 pods 我想重新启动有一个 Gunicorn-server 运行ning 需要重新加载一些数据。这仅在服务器重新启动时有效。

gunicorn 服务在 Dockerfile 中启动:

CMD gunicorn -c gunicorn.conf.py -b :$PORT --preload app:app

但我猜这不太相关。

我认为解决方案是我可以在 Python 脚本中 运行 的某种 kubectl 命令,或者我找不到的 kubectl 端点提示。

kubectl rollout restart 已经登陆 Kubernetes v1.15 [1]。此功能专为您的目的而设计 - pods.

的滚动重启

[1] https://github.com/kubernetes/kubernetes/issues/13488