0

假设我们有许多在 k8s 上运行的微服务,其部署、服务和入口可通过 api.localhost 上的 kong 入口网关访问。

每个微服务都在特定路径上运行,例如

  • api.localhost/foo对于 foo 微服务
  • api.localhost/bar用于酒吧微服务

如何使用带有 Kong 网络层的 Knative 来实现这一点?像这样的东西不起作用:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: foo-api  
  labels:
    networking.knative.dev/visibility: cluster-local
spec:
  template:    
    spec:
      containers:
        - image: foo-image
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:    
    kubernetes.io/ingress.class: kong
    konghq.com/strip-path: "true"
    ingress.kubernetes.io/service-upstream: "true"
  name: foo  
spec:
  rules:
    - host: api.localhost
      http:
        paths:
          - backend:
              service:
                name: foo-api
                port:
                  number: 80
            path: /foo
            pathType: ImplementationSpecific

https://github.com/Kong/kubernetes-ingress-controller/issues/584 https://knative.dev/docs/serving/samples/knative-routing-go/

4

1 回答 1

0

我找到了这个解决方案

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: knative-service-test
  namespace: default
spec:
  template:
    spec:
      containers:
        - image: ealen/echo-server:latest
---
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: request-transformer-example
  namespace: kong
plugin: request-transformer
config:
  replace:
    headers:
      - 'host:knative-service-test.default.example.com'
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demo
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
    plugins.konghq.com: request-transformer-example
spec:
  rules:
  - http:
      paths:
      - path: /temp
        backend:
          serviceName: kong-proxy
          servicePort: 80

https://github.com/Kong/kubernetes-ingress-controller/issues/706

但是在多租户问题上,我的服务中需要正确的主机头。

于 2021-05-21T09:32:34.253 回答