简体   繁体   English

nginx 入口 504 超时运行多 pod

[英]nginx ingress 504 timeout with running multi pod

I am running 2 pod(replicas) of particular deployment on Kubernetes with nginx ingress.我正在使用 nginx 入口在 Kubernetes 上运行 2 个特定部署的 pod(副本)。 Service using web socket also.服务也使用 web 插座。

Out of 2 pod I have deleted one pod so it starts creating again while 1 was in a ready state.在 2 个 pod 中,我删除了一个 pod,因此它再次开始创建,而 1 位于准备好的 state 中。 In between this, I tried to open the URL and got an error 504 gateway timeout.在此期间,我尝试打开 URL 并收到错误 504 网关超时。

As per my understanding traffic has to divert to Ready state pod from Kubernetes service.据我了解,流量必须从 Kubernetes 服务转移到 Ready state pod。 Am I missing something please let me know?我错过了什么请告诉我吗?

Thanks in advance.提前致谢。

Here is my ingress if any mistake如果有任何错误,这是我的入口

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: core-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    certmanager.k8s.io/cluster-issuer: core-prod
    nginx.ingress.kubernetes.io/proxy-body-size: 50m
    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/secure-backends: "true"
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/websocket-services: core
    nginx.org/websocket-services: core
spec:
  tls:
  - hosts:
    - app.wotnot.io
    secretName: core-prod
  rules:
  - host: example.io
    http:
      paths:
      - backend:
          serviceName: core
          servicePort: 80

Services do not guarantee 100% uptime, especially if there are only 2 pods.服务不能保证 100% 的正常运行时间,尤其是在只有 2 个 pod 的情况下。 Depending on the timing of your request, one of a number of possible outcomes is occurring.根据您提出请求的时间,会出现多种可能结果中的一种。

  1. You try to open the URL before the pod is marked as notReady.您尝试在 pod 标记为 notReady 之前打开 URL。 What happens, in this case, is your service forwards the request to your pod which is about to terminate.在这种情况下,您的服务会将请求转发到即将终止的 Pod。 Since the pod is about to terminate and the webserver is shutting down, the pod is no longer able to respond so nginx responds with 504. It is also possible that a session is already started with this pod and it is interrupted because of the sigterm .由于 pod 即将终止并且 webserver 正在关闭,因此 pod 不再能够响应,因此 nginx 响应为 504。也有可能 session 已经使用此 pod 启动,并且由于sigterm而中断。

  2. You send a request once the second pod is in terminating state.一旦第二个 pod 终止 state,您就发送一个请求。 Your primary pod is being overworked from handling 100% of the requests so a response does not come fast enough so nginx returns an error.您的主 pod 因处理 100% 的请求而过度工作,因此响应速度不够快,因此 nginx 返回错误。

In any scenario, your best option is to check the nginx ingress container logs to see why 504 is being returned so you can further debug this.在任何情况下,您最好的选择是检查 nginx 入口容器日志,了解返回 504 的原因,以便进一步调试。

Note that, as mentioned just above, services do only include pods marked as Ready, however, this does not guarantee that 100% of requests will always be served correctly.请注意,如上所述,服务仅包括标记为 Ready 的 Pod,但是,这并不能保证 100% 的请求将始终得到正确服务。 Any time a pod is taken down for any reason, there is always a chance that a 5xx error is returned.每当一个 pod 因任何原因被关闭时,总是有可能返回 5xx 错误。 Having a greater number of pods will reduce the odds of an error being returned but it will rarely completely eliminate the odds.拥有更多数量的 pod 会降低返回错误的几率,但它很少会完全消除这种几率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM