GKE Ingress 获取 pod 的速度很慢 readiness/liveness
GKE Ingress is slow to pick up pod readiness/liveness
我成功地使用 gce ingress 使用 GKE 创建了一个集群。然而 Ingress 需要很长时间才能检测到服务就绪(我已经设置了 livenessProbe 和 readinessProbe)。
我的 pods 设置
Containers:
...
gateway:
Liveness: http-get http://:5100/api/v1/gateway/healthz delay=0s timeout=1s period=10s #success=1 #failure=3
Readiness: http-get http://:5100/api/v1/gateway/healthz delay=0s timeout=1s period=10s #success=1 #failure=3
...
和入口
...
Name: main-ingress
Host Path Backends
---- ---- --------
<host>
/api/v1/gateway/ gateway:5100 (<ip:5100>)
/api/v1/gateway/* gateway:5100 (<ip:5100>)
web:80 (<ip>)
Annotations:
ingress.kubernetes.io/backends: {"k8s-be-***":"HEALTHY","k8s-be-***":"HEALTHY","k8s-be-***":"HEALTHY"}
kubernetes.io/ingress.allow-http: false
我注意到,如果我杀死所有服务并重新部署,后端会在 UNHEALTHY
上停留相当长的一段时间,然后再启动它,即使 Kubernetes 本身设法启动了 pods/service都是运行
我也注意到设置livenessProbe
和readinessProbe
时,ingress-gce生成的后端健康检查如下
Backend
Timeout: 30 seconds
Backend Health check
Interval: 70 seconds
Timeout: 1 second
Unhealthy threshold: 10 consecutive failures
Healthy threshold: 1 success
而如果我只是部署一个简单的 nginx pod 而不指定 livenessProbe
和 readinessProbe
,生成的后端如下
Backend
Timeout: 30 seconds
Backend Health Check
Interval: 60 seconds
Timeout: 60 seconds
Unhealthy threshold: 10 consecutive failures
Healthy threshold: 1 success
后台健康检查是导致取东西慢的根本原因吗?如果是这样,知道如何加快速度吗?
更新
看完想澄清
我知道创建新入口时需要更长的时间,因为入口控制器需要提供新的负载均衡器、后端和所有其他相关的东西。
但是我还注意到,当我发布新版本的服务时(通过 Helm - 部署设置为 Recreate 而不是 RollingUpgrade)或者如果 pod 死亡(内存不足)并重新启动,它需要尽管 Pod 已经处于 running/healthy 状态(这是 GCP 中现有的 Ingress 和 Load Balancer),但后端状态再次恢复健康之前的相当长一段时间。有没有办法加快速度?
使用 GCE Ingress 时,您需要等待负载均衡器配置时间才能将 backend service 视为健康。
请考虑一下,当您使用此入口 class 时,您依赖的 GCE 基础架构必须在将请求发送到集群之前自动配置 HTTP(S) load balancer 及其所有组件。
当您在没有 readinessProbe
的情况下设置部署时,默认值将应用于负载均衡器运行状况检查:
Backend Health Check
Interval: 60 seconds
Timeout: 60 seconds
Unhealthy threshold: 10 consecutive failures
Healthy threshold: 1 success
但是,使用readinessProbe
will add the periodSeconds
value to the default health check configuration。因此,在您的情况下,默认情况下您有 10
秒 + 60
= 70
.
Backend Health check
Interval: 70 seconds
Timeout: 1 second
Unhealthy threshold: 10 consecutive failures
Healthy threshold: 1 success
请注意,GKE 只会使用 readinessProbe
来设置负载均衡器中的健康检查。 Liveness从不被挑选。
这意味着,最低值将始终是默认负载均衡器健康检查的值,60
。由于这些值是在从 GKE 调用负载均衡器时自动设置的,因此无法更改它们。
最后,您必须等待负载均衡器配置期(大约 1-3 分钟)加上 readinessProbe
中设置的 periodSeconds
值。
我成功地使用 gce ingress 使用 GKE 创建了一个集群。然而 Ingress 需要很长时间才能检测到服务就绪(我已经设置了 livenessProbe 和 readinessProbe)。 我的 pods 设置
Containers:
...
gateway:
Liveness: http-get http://:5100/api/v1/gateway/healthz delay=0s timeout=1s period=10s #success=1 #failure=3
Readiness: http-get http://:5100/api/v1/gateway/healthz delay=0s timeout=1s period=10s #success=1 #failure=3
...
和入口
...
Name: main-ingress
Host Path Backends
---- ---- --------
<host>
/api/v1/gateway/ gateway:5100 (<ip:5100>)
/api/v1/gateway/* gateway:5100 (<ip:5100>)
web:80 (<ip>)
Annotations:
ingress.kubernetes.io/backends: {"k8s-be-***":"HEALTHY","k8s-be-***":"HEALTHY","k8s-be-***":"HEALTHY"}
kubernetes.io/ingress.allow-http: false
我注意到,如果我杀死所有服务并重新部署,后端会在 UNHEALTHY
上停留相当长的一段时间,然后再启动它,即使 Kubernetes 本身设法启动了 pods/service都是运行
我也注意到设置livenessProbe
和readinessProbe
时,ingress-gce生成的后端健康检查如下
Backend
Timeout: 30 seconds
Backend Health check
Interval: 70 seconds
Timeout: 1 second
Unhealthy threshold: 10 consecutive failures
Healthy threshold: 1 success
而如果我只是部署一个简单的 nginx pod 而不指定 livenessProbe
和 readinessProbe
,生成的后端如下
Backend
Timeout: 30 seconds
Backend Health Check
Interval: 60 seconds
Timeout: 60 seconds
Unhealthy threshold: 10 consecutive failures
Healthy threshold: 1 success
后台健康检查是导致取东西慢的根本原因吗?如果是这样,知道如何加快速度吗?
更新
看完想澄清
我知道创建新入口时需要更长的时间,因为入口控制器需要提供新的负载均衡器、后端和所有其他相关的东西。
但是我还注意到,当我发布新版本的服务时(通过 Helm - 部署设置为 Recreate 而不是 RollingUpgrade)或者如果 pod 死亡(内存不足)并重新启动,它需要尽管 Pod 已经处于 running/healthy 状态(这是 GCP 中现有的 Ingress 和 Load Balancer),但后端状态再次恢复健康之前的相当长一段时间。有没有办法加快速度?
使用 GCE Ingress 时,您需要等待负载均衡器配置时间才能将 backend service 视为健康。
请考虑一下,当您使用此入口 class 时,您依赖的 GCE 基础架构必须在将请求发送到集群之前自动配置 HTTP(S) load balancer 及其所有组件。
当您在没有 readinessProbe
的情况下设置部署时,默认值将应用于负载均衡器运行状况检查:
Backend Health Check
Interval: 60 seconds
Timeout: 60 seconds
Unhealthy threshold: 10 consecutive failures
Healthy threshold: 1 success
但是,使用readinessProbe
will add the periodSeconds
value to the default health check configuration。因此,在您的情况下,默认情况下您有 10
秒 + 60
= 70
.
Backend Health check
Interval: 70 seconds
Timeout: 1 second
Unhealthy threshold: 10 consecutive failures
Healthy threshold: 1 success
请注意,GKE 只会使用 readinessProbe
来设置负载均衡器中的健康检查。 Liveness从不被挑选。
这意味着,最低值将始终是默认负载均衡器健康检查的值,60
。由于这些值是在从 GKE 调用负载均衡器时自动设置的,因此无法更改它们。
最后,您必须等待负载均衡器配置期(大约 1-3 分钟)加上 readinessProbe
中设置的 periodSeconds
值。