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

如何在Kubernetes中部署Envoy作为负载均衡器并解决配置错误

问题解决:Envoy Proxy作为Kubernetes负载均衡器配置错误修复

错误原因

错误日志(static_resources.clusters[0]) hosts: Cannot find field.是因为你使用的Envoy版本采用了v3 API规范,v3已废弃在clusters节点下直接配置hosts的方式,且你修改后的配置格式不符合v3 API要求。

正确的Envoy配置调整

以下是修正后的完整Envoy配置,重点调整了集群配置结构与API版本适配:

static_resources:
  listeners:
  - name: listener_0
    address:
      socket_address:
        protocol: TCP
        address: 0.0.0.0
        port_value: 10000
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          access_log:
          - name: envoy.access_loggers.file
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
              path: /var/log/envoy/access.log
          stat_prefix: ingress_http
          codec_type: AUTO
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              routes:
              - match: { prefix: "/f" }
                route: { host_rewrite_literal: files, cluster: co_clusters, timeout: 60s }
          http_filters:
          - name: envoy.filters.http.router
            typed_config: {}

  clusters:
  - name: co_clusters
    connect_timeout: 0.25s
    type: STRICT_DNS
    dns_lookup_family: V4_ONLY
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: co_clusters
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: files.default.svc.cluster.local
                port_value: 80

关键调整说明

  1. API版本适配:将v2风格的过滤器名称(如envoy.http_connection_manager)替换为v3规范名称,通过typed_config和@type字段明确配置类型,匹配Envoy v3 API要求。
  2. 集群后端配置:把后端地址从hosts迁移到load_assignment -> endpoints -> lb_endpoints结构中,这是v3 API规定的标准集群后端配置格式。
  3. DNS与端口明确:指定Kubernetes Service的完整DNS域名files.default.svc.cluster.local和对应80端口,确保Envoy能正确解析到目标Service。
  4. 路由字段修正:将host_rewrite替换为v3规范的host_rewrite_literal字段。

验证步骤

  1. 用修正后的配置替换原Envoy配置文件。
  2. 重启Envoy Pod,检查日志确认启动成功。
  3. 向Envoy的10000端口/f路径发送请求,验证是否能正确转发到files Service对应的Pod。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 07:20:42