Skip to content

Instantly share code, notes, and snippets.

@pmbanugo
Created January 29, 2022 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmbanugo/ba8034f2922282dcc79b552fb6512df1 to your computer and use it in GitHub Desktop.
Save pmbanugo/ba8034f2922282dcc79b552fb6512df1 to your computer and use it in GitHub Desktop.
Kong Ingress Route to multiple ksvc based on path & HTTP Method
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: hello-service-host-rewrite
# The plugin must be created in the same namespace as the ingress.
namespace: kong
plugin: request-transformer
config:
add:
headers:
- 'Host: hello.default.svc.cluster.local'
replace:
headers:
- 'Host: hello.default.svc.cluster.local'
---
# Create a Kong request transformer plugin to rewrite the original host header
# to the host header of Login service in order to redirect requests to Login
# service.
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: hi-service-host-rewrite
# The plugin must be created in the same namespace as the ingress.
namespace: kong
plugin: request-transformer
config:
add:
headers:
- 'Host: hi.default.svc.cluster.local'
replace:
headers:
- 'Host: hi.default.svc.cluster.local'
---
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: hello-service-host-rewrite
route:
methods:
- GET
- OPTIONS
protocols:
- http
---
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: hi-service-host-rewrite
route:
methods:
- POST
strip_path: true
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hi-hello-post
# The ingress must be created in the same namespace as the kong-proxy service.
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
konghq.com/override: hi-service-host-rewrite
konghq.com/plugins: hi-service-host-rewrite
spec:
rules:
- host: hi-hello.localhost
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: kong-proxy
port:
number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hi-hello-get
# The ingress must be created in the same namespace as the kong-proxy service.
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
konghq.com/methods: GET
konghq.com/plugins: hello-service-host-rewrite
spec:
rules:
- host: hi-hello2.localhost
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: kong-proxy
port:
number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hi-hello-get-2
# The ingress must be created in the same namespace as the kong-proxy service.
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
konghq.com/methods: POST
konghq.com/plugins: hi-service-host-rewrite
spec:
rules:
- host: hi-hello2.localhost
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: kong-proxy
port:
number: 80
@pmbanugo
Copy link
Author

hi-hello2.localhost host shows exactly what I'm trying to achieve. Apparently, I can't use KongIngress in both Ingress definition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment