如何配置确保Knative queue-proxy不发生60秒请求超时?
从你提供的错误日志和配置来看,核心问题是Knative queue-proxy的默认60秒超时没有被正确覆盖——即使你在Service中设置了timeoutSeconds: 500,还需要额外配置queue-proxy本身以及Istio的超时参数来匹配。以下是具体的解决步骤:
1. 显式配置queue-proxy的超时时间
在Knative v0.11.0中,queue-proxy默认使用60秒的超时,这个值不会自动继承Service的timeoutSeconds,需要通过注解显式设置。修改你的Knative Service配置,在template.metadata.annotations中添加queue-proxy的超时注解:
apiVersion: serving.knative.dev/v1 kind: Service metadata: name: sleeper-service spec: template: metadata: annotations: autoscaling.knative.dev/maxScale: "1" # 显式设置queue-proxy的超时时间,与timeoutSeconds保持一致 queue.serving.knative.dev/timeout-seconds: "500" spec: containerConcurrency: 0 containers: - env: - name: MILLISECONDS value: "330000" image: <image> name: user-container ports: - containerPort: 8000 name: http1 protocol: TCP readinessProbe: successThreshold: 1 tcpSocket: port: 0 resources: {} timeoutSeconds: 500 traffic: - latestRevision: true percent: 100
这个注解会直接覆盖queue-proxy的默认60秒超时,让它和你设置的服务整体超时保持一致。
2. 调整Istio的超时配置
由于你使用的是Istio 1.3.5,Istio的VirtualService默认也可能有60秒的超时设置,需要同步调整来避免链路中的超时截断。你可以为你的Knative Service创建对应的VirtualService(或者修改Knative自动生成的VirtualService),设置更长的超时:
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: sleeper-service spec: hosts: - sleeper-service.default.svc.cluster.local - sleeper-service.default.example.com # 替换成你的实际域名 http: - route: - destination: host: sleeper-service.default.svc.cluster.local timeout: 500s # 与Knative的超时时间匹配
如果Knative已经自动生成了VirtualService,你可以编辑它并添加这个timeout字段。
3. 验证配置生效
更新配置后,重新部署你的Service:
kubectl apply -f your-service.yaml
然后查看queue-proxy的环境变量,确认超时是否被正确设置:
kubectl exec -it <your-pod-name> -c queue-proxy -- env | grep QUEUE_TIMEOUT
你应该能看到QUEUE_TIMEOUT=500s的输出,这说明配置已经生效。
补充说明
当你设置containerConcurrency: 0(无限制并发)且maxScale: 1时,所有请求都会在同一个Pod的queue-proxy中排队,此时如果queue-proxy的超时过短,就会导致排队的请求被提前截断。确保上述所有超时配置保持一致(都设置为500秒),就能避免60秒的超时问题。
内容的提问来源于stack exchange,提问作者Anirudh Alampally

