【问题标题】:Equivalents of Nginx Ingress Annonations on IstIO Ingress GatewayIstIO Ingress Gateway 上的 Nginx Ingress Annonations 等价物
【发布时间】:2019-11-27 12:51:15
【问题描述】:

我目前正在将 IT 环境从 Nginx Ingress Gateway 迁移到 Kubernetes 上的 IstIO Ingress Gateway。

我需要迁移以下 Nginx 注释:

nginx.ingress.kubernetes.io/proxy-buffer-size
nginx.ingress.kubernetes.io/proxy-read-timeout
nginx.ingress.kubernetes.io/proxy-send-timeout
nginx.ingress.kubernetes.io/proxy-body-size
nginx.ingress.kubernetes.io/upstream-vhost

对于 Nginx,注释记录在这里:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/

在 IstIO 的 Nginx 注解的文档中没有找到 IstIO Ingress Gateway 的使用方式。

有人知道如何在 IstIO Ingress Gateway 中实现上述注解吗?

【问题讨论】:

    标签: kubernetes istio nginx-ingress


    【解决方案1】:

    我想我找到了如何在 Istio 中设置 nginx.ingress.kubernetes.io/proxy-body-size。

    apiVersion: networking.istio.io/v1alpha3
    kind: EnvoyFilter
    metadata:
      name: reviews-lua
      namespace: bookinfo
    spec:
      workloadSelector:
        labels:
          app: reviews
      configPatches:
        # The first patch adds the lua filter to the listener/http connection manager
      - applyTo: HTTP_FILTER
        match:
          context: SIDECAR_INBOUND
          listener:
            portNumber: 8080
            filterChain:
              filter:
                name: "envoy.http_connection_manager"
                subFilter:
                  name: "envoy.router"
        patch:
          operation: INSERT_BEFORE
          value: # lua filter specification
           name: envoy.lua
           config:
             inlineCode: |
               function envoy_on_request(request_handle)
                 request_handle:headers():add("request_body_size", request_handle:body():length())
               end
    

    还有 TLS 密码:

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: my-tls-ingress
    spec:
      selector:
        app: my-tls-ingress-gateway
      servers:
      - port:
          number: 443
          name: https
          protocol: HTTPS
        hosts:
        - "*"
        tls:
          mode: SIMPLE
          serverCertificate: /etc/certs/server.pem
          privateKey: /etc/certs/privatekey.pem
          cipherSuites: "<tls-ciphers>"
    

    【讨论】:

    • 这对你有用吗?对我来说,它给出了 ``` [string "function envoy_on_request(request_handle)..."]:3: 尝试在 get 请求中索引一个 nil 值`` 并且在 post 请求中没有显示任何标头并返回 http 错误 413跨度>
    【解决方案2】:

    如果您收到 413 Entity Too Large 作为响应,这种情况的主要问题是链中的 Envoy 过滤器之一有缓冲。

    您可以在这里找到有关该问题的讨论:https://github.com/envoyproxy/envoy/issues/2919

    Envoy 上缓冲的初始值由属性设置:

      http2_protocol_options:
        initial_stream_window_size: 65536 # 64 KiB
        initial_connection_window_size: 1048576 # 1 MiB
    

    来源:https://www.bookstack.cn/read/envoyproxy-1.13/9a624d80e56eceef.md

    您可以为给定的工作负载(或全局)覆盖该缓冲区,但您必须记住,如果增加太多,则存在内存不足攻击的风险。

    重新配置过滤器的示例:

    apiVersion: networking.istio.io/v1alpha3
    kind: EnvoyFilter
    metadata:
      name: my-service
    spec:
      workloadSelector:
        labels:
          app: my-service
      configPatches:
        - applyTo: NETWORK_FILTER
          match:
            listener:
              filterChain:
                filter:
                  name: "envoy.http_connection_manager"
          patch:
            operation: MERGE
            value:
              typed_config:
                "@type": "type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager"
                http2_protocol_options:
                  initial_stream_window_size: 65536
                  initial_connection_window_size: 10485760 # 10 MB
    

    您将在 Istio 文档中找到有关 Envoy Filers 的更多信息:https://istio.io/latest/docs/reference/config/networking/envoy-filter/

    其他示例:https://github.com/istio/istio/wiki/EnvoyFilter-Samples

    【讨论】:

      【解决方案3】:

      可以在 Istio 中使用 Envoy Filter 实现 Nginx 入口注解等效项。

      更具体地说,使用HTTP Lua filter。

      具有 HTTP Lua 过滤器的特使过滤器示例:

      apiVersion: networking.istio.io/v1alpha3
      kind: EnvoyFilter
      metadata:
        name: reviews-lua
        namespace: bookinfo
      spec:
        workloadSelector:
          labels:
            app: reviews
        configPatches:
          # The first patch adds the lua filter to the listener/http connection manager
        - applyTo: HTTP_FILTER
          match:
            context: SIDECAR_INBOUND
            listener:
              portNumber: 8080
              filterChain:
                filter:
                  name: "envoy.http_connection_manager"
                  subFilter:
                    name: "envoy.router"
          patch:
            operation: INSERT_BEFORE
            value: # lua filter specification
             name: envoy.lua
             config:
               inlineCode: |
                 function envoy_on_request(request_handle)
                   -- Make an HTTP call to an upstream host with the following headers, body, and timeout.
                   local headers, body = request_handle:httpCall(
                    "lua_cluster",
                    {
                     [":method"] = "POST",
                     [":path"] = "/acl",
                     [":authority"] = "internal.org.net"
                    },
                   "authorize call",
                   5000)
                 end
        # The second patch adds the cluster that is referenced by the lua code
        # cds match is omitted as a new cluster is being added
        - applyTo: CLUSTER
          match:
            context: SIDECAR_OUTBOUND
          patch:
            operation: ADD
            value: # cluster specification
              name: "lua_cluster"
              type: STRICT_DNS
              connect_timeout: 0.5s
              lb_policy: ROUND_ROBIN
              hosts:
              - socket_address:
                  protocol: TCP
                  address: "internal.org.net"
                  port_value: 8888
      

      例如:

      nginx.ingress.kubernetes.io/proxy-body-size 可以通过size = buffer:length() 实现。

      nginx.ingress.kubernetes.io/proxy-read-timeout 或 nginx.ingress.kubernetes.io/proxy-send-timeout 是自定义超时,可以通过 httpCall(5000) 实现。

      方法的完整列表可以在here找到。

      希望这会有所帮助。


      更新:

      重读 nginx 注释后,getBytes() 看起来更适合nginx.ingress.kubernetes.io/proxy-buffer-size 而不是buffer:lenght()。

      getBytes()

      缓冲区:getBytes(索引,长度)

      从缓冲区中获取字节。默认情况下,Envoy 不会复制所有缓冲区 字节到 Lua。这将导致复制缓冲区段。 索引 是一个整数并提供要复制的缓冲区起始索引。 长度 是一个整数并提供要复制的缓冲区长度。 索引 + 长度必须小于缓冲区长度。

      所以buffer:getBytes(0, 8000) 应该从类似于nginx.ingress.kubernetes.io/proxy-buffer-size: "8k" 的缓冲区加载8k 字节。

      【讨论】:

      • 谢谢,这很有帮助,虽然它与 Nginx 注释相比非常复杂。
      • 你能举例说明如何使用size = buffer:length()吗?我没有从文档中得到它。我想设置代理服务器的缓冲区大小。
      • 我已经编辑了我的答案来解决您的其他问题。还修复了第一个示例。我的示例只是我无法验证它们是否有效的建议。
      • 好的,谢谢。以及如何在 IstIO 中实现nginx.ingress.kubernetes.io/proxy-body-size?
      • 以及如何在Istio中实现注解nginx.ingress.kubernetes.io/ssl-ciphers?
      猜你喜欢
      • 1970-01-01
      • 2021-09-10
      • 2021-01-23
      • 2020-06-11
      • 1970-01-01
      • 2020-06-25
      • 2020-08-09
      • 2020-10-16
      • 2021-06-30
      相关资源
      最近更新 更多