1

Let's say we have many microservices running on k8s with deployments, services and ingresses accessible with kong ingress gateway on api.localhost.

Each microservice run on specific path, e.g.

  • api.localhost/foo for foo microservice
  • api.localhost/bar for bar microservice

How to achieve this with Knative with Kong network layer? Something like this doesn't work:

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/

manro
  • 43
  • 4

1 Answers1

1

I found this solution

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: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demo
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
    konghq.com/plugins: request-transformer-example
spec:
  rules:
  - http:
      paths:
      - path: /temp
        pathType: Prefix
        backend:
          service: 
            name: kong-proxy
            port: 80

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

But I need the correct host header in my service in a matter of multi-tenancy.

LaloLoop
  • 2,143
  • 3
  • 12
  • 18
manro
  • 43
  • 4