KongIngress 对象中的 strip_path 和 preserve_host 属性。他们在做什么?

bga*_*ial 0 basic-authentication kong kubernetes-ingress kong-plugin kong-ingress

我有一个KongIngress关于 Ingress 资源的对象配置属性,它调用 kong 作为 Ingress 控制器。我实际上有这个配置:

apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
  name: echo-site-ingress
  namespace: hello-world
  annotations:
    kubernetes.io/ingress.class: "kong"
proxy:
  protocols:
    - http
    - https
#  path: /
route:
  methods:
    - POST
    - GET
  strip_path: true
  preserve_host: true
---
#My Ingress resource
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    kubernetes.io/ingress.class: kong
    plugins.konghq.com: helloworld-customer-acceptance-basic-auth, hello-world-customer-acceptance-acl
  name: echo-site-ingress
  namespace: hello-world
spec:
  rules:
  - host: hello-world.bgarcial.me
    http:
      paths:
      - backend:
          serviceName: echo
          servicePort: 80
        path: /
  tls: 
  - hosts:
    - hello-world.bgarcial.me
    secretName: letsencrypt-prod
Run Code Online (Sandbox Code Playgroud)

问题是:

我的kind:KongIngress对象资源strip_pathpreserve_host属性在做什么?

我在这里阅读了文档,但我不清楚:

关于strip_path 我看到这个:

通过其中一个路径匹配 Route 时,从上游请求 URL 中去除匹配的前缀。默认为真。但正如我们所看到的,我没有在我的 KongIngress 对象中使用 path 属性(我为了说明目的而对我的问题进行了评论)

那么,strip_path这里如何应用属性值呢?

这是因为我在我的 Ingress 资源中使用了该path: /属性,并且我的 Ingress 和我的 KongIngress 资源正在协同工作?

我真的对此一无所知,但我想知道幕后情况如何。

Mar*_* K. 7

preserv_host注释被使能host请求的报头将被发送为的是在Kubernetes服务。文档中有很好的解释。

strip_path 可以配置为在代理之前从 HTTP 请求中去除路径的匹配部分。

如果设置为"true",则在将请求发送到服务之前,将剥离 Ingress 规则中指定的路径部分。例如,设置为 时"true",Ingress 规则的路径为 /foo ,与 Ingress 规则匹配的 HTTP 请求的路径为 /foo/bar/something,则发送到 Kubernetes 服务的请求的路径为 /bar/something。因此,当您使用curl $YOUR_HOST/foo/bar/something, 在输出中的真实路径值下,您将看到/bar/something

如果设置为false不执行路径操作,并且在您的情况下可以更改为例如无需进行任何操作。

  • 对于 kubernetes 入口控制器,您需要将 `konghq.com/strip-path: true` 添加到 `annotations` (2认同)