You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Kong Ingress 3.1.x中修改上游超时?配置遇解码错误

问题描述

在Kong Ingress 2.7.x版本中,我通过upstream-timeout插件配置上游超时,配置如下:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: up-timeout
  annotations:
    kubernetes.io/ingress.class: kong
  labels:
    global: "true"
plugin: upstream-timeout
config:
  connect_timeout: 30000
  send_timeout: 3600000
  read_timeout: 3600000

升级至3.1.x后,尝试在Service的YAML中通过注解配置超时:

apiVersion: v1
kind: Service
metadata:
  name: logistics-simulator
  annotations:
    konghq.com/override: kong-timeout
    konghq.com/connect-timeout: 3600000
spec:
    type: ClusterIP
    ports:
    - port: 80 
    selector:
        app: logistics-simulator

但在AKS环境中遇到解码错误:

error: unable to decode "/home/vsts/work/_temp/Service_logistics-simulator_1712325946614": json: cannot unmarshal number into Go struct field ObjectMeta.metadata.annotations of type string
##[error]error: unable to decode "/home/vsts/work/_temp/Service_logistics-simulator_1712325946614": json: cannot unmarshal number into Go struct field ObjectMeta.metadata.annotations of type string

请问该如何正确配置Kong Ingress 3.1.x的上游超时?

正确配置方式

方式一:修正Service注解格式

Kubernetes的注解值必须为字符串类型,你当前配置的3600000是数字类型,导致解码失败。只需把超时值用引号包裹转为字符串即可:

apiVersion: v1
kind: Service
metadata:
  name: logistics-simulator
  annotations:
    konghq.com/override: kong-timeout
    konghq.com/connect-timeout: "3600000"  # 转为字符串格式
    konghq.com/send-timeout: "3600000"     # 按需添加发送超时
    konghq.com/read-timeout: "3600000"     # 按需添加读取超时
spec:
    type: ClusterIP
    ports:
    - port: 80 
    selector:
        app: logistics-simulator

方式二:继续使用KongPlugin配置(兼容旧版本)

Kong Ingress 3.1.x依然支持upstream-timeout插件的配置方式,如果你习惯原有逻辑,可继续使用该方案:

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: up-timeout
  annotations:
    kubernetes.io/ingress.class: kong
  labels:
    global: "true"  # 全局生效,若需局部绑定可移除该标签
plugin: upstream-timeout
config:
  connect_timeout: 30000
  send_timeout: 3600000
  read_timeout: 3600000

若不需要全局生效,可在目标Service或Ingress中添加注解konghq.com/plugins: up-timeout,实现插件的局部绑定。

内容的提问来源于stack exchange,提问作者whebz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 03:02:35