如何防止 Istio sidecar 在我的服务正常终止之前关闭?

How can I prevent Istio sidecar from shutting down before my service has finished gracefully terminating?

我们有一项服务在关闭时需要 运行 一些更长的 SQL 查询。但是,当 pod 从 Kubernetes 收到 SIGTERM 时,istio 代理容器在关闭前仅等待 5 秒。这会导致我们的查询失败并且服务无法正常终止。

我们尝试过的事情:

我们怎样才能让 Istio 保持 运行ning 足够长的时间让我们的服务正常终止,而不是让它保持 运行ning 太长

据我所知,不幸的是 Graceful shutdown 不支持 istio sidecar:

Currently there is not. This seems like an interesting feature request though, it may be worth a feature request on github.

我也认为在 github 上设置一个合适的线程将是一个解决方案。 我知道的唯一方法是使用 TERMINATION_DRAIN_DURATION_SECONDS 选项。

在 github 上还有几个主题与此主题相关:

istio-proxy stop before my containers #10112

And currently envoy does not support graceful shutdown. xref: envoyproxy/envoy#2920 Once envoy implements this, we can support it in sidecar.


Render istio-proxy environment variables from global.proxy.env or environmentOverride annotation #18333

For anyone looking through issues for why their connection to a pod is disconnecting early, hopefully this helps.

You need the pod to have a terminationGracePeriodSeconds, which I assume you were already aware about, and you also need an annotation for the pod's sidecar config:

annotations: # https://istio.io/latest/docs/reference/config/istio.mesh.v1alpha1/#ProxyConfig proxy.istio.io/config: | terminationDrainDuration: {{ $terminationGracePeriodSeconds }}s


Envoy shutting down before the thing it's wrapping can cause failed requests #7136

Graceful shutdown with injected envoy-sidecar #536