I am a new beginner for Kubernetes and kong, and i want to route my traffic to different backend service based on the request headers, and i try below setup, but it didnt work, so please kindly advised what i should to do. Thanks.
kongingress.yaml
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: a-routing
route:
headers:
x-custom-header:
- jason
ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo
annotations:
kubernetes.io/ingress.class: kong
konghq.com/override : a-routing
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: echo
servicePort: 80
and if i try to use curl -i -H “x-custom-header: jason” it will shows no route matched these values.
fomm
September 7, 2021, 2:25pm
2
This should work. I just did a quick test as below
---
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: update-header
route:
headers:
x-custom-header:
- jason
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo
annotations:
kubernetes.io/ingress.class: kong
konghq.com/override : update-header
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: demo-svc
servicePort: 80
and it was working fine.
What can you see from log?
I tried the same thing → This is my configuration → I have a header connectionID in the request body and want to route based on this → How would I do that? Pretty new to Kong
---
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: update-header
namespace: my
route:
methods:
- POST
- GET
strip_path: true
preserve_host: true
protocols:
- http
- https
headers:
Connectionid:
- $Connectionid
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ing
namespace: my
labels:
app: my-app
chart: my-app:1.0.0
release: my-app
heritage: Tiller
annotations:
kubernetes.io/ingress.class: kong
konghq.com/strip-path: "true"
konghq.com/override : update-header
nlb.ingress.kubernetes.io/actions.ssl-redirect: "false"
spec:
tls:
- hosts:
- host.com
secretName: secretName
rules:
- host: host.com
http:
paths:
- path: /path
pathType: ImplementationSpecific
backend:
service:
name: my-service
port:
number: 80
fomm
September 13, 2021, 12:41pm
4
Kaustubh_Sharma:
$Connectionid
Is $Connectionid
a variable? You can only use static values. In your setting $Connectionid
is the value to match.
curl <Kong_Proxy>/path -H 'Connectionid:$Connectionid' -i
HTTP/1.1 200 OK
If you have more than 1 values that you want to match, you just add move values like below.
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: update-header
route:
headers:
x-custom-header:
- jason
- bob
Yes connectionID is a variable
Is there are way to route based on connectionID using KongIngress or any other method?