I am trying to convert some logic written in kubernetes ingress configuration yaml files.
In latest versions of k8s, keywords that are with "-snippets" values are identified as risky one (e.g. configuration-snippet, auth-snippet, etc).
I have one use case, where am using header based approach to navigate to service, only if specific header is present in the request (this was earlier written using ingress object).
I tried out approach using Gateway API and HTTPRoute objects which supports header based routing, but for that i had to add explicit CRT's via helm and those doesn't come directly with k8s.
I don't want to go with this approach though, and also paths are not supposed to be changed.
How to fix this using classic ingress approach such that no any path changes will be needed.
Please find the configuration I was trying out
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: i-nginx-gateway
namespace: my-namespace
spec:
gatewayClassName: nginx
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: i-app-route
namespace: my-namespace
spec:
parentRefs:
- name: i-nginx-gateway
namespace: my-namespace
hostnames:
- something.com
rules:
# Rule 1: Authorization header present → go through asvc
- matches:
- path:
type: PathPrefix
value: /i/(.*)
headers:
- name: authtype
type: Exact
value: my-jwt
backendRefs:
- name: asvc
port: 8000
# Rule 2: No Authorization header → go directly to i
- matches:
- path:
type: PathPrefix
value: /i/(.*)
backendRefs:
- name: i
port: 8000
Tried to use canary ingress approach, but somehow request are hitting primary ing only and not canary one. Added config that i am trying out.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: i-direct-ingress
namespace: mynamespace
spec:
ingressClassName: nginx
rules:
- host: something.com
http:
paths:
- path: /i
pathType: Prefix
backend:
service:
name: i
port:
number: 8000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: i-canary-ingress
namespace: mynamespace
annotations:
nginx.ingress.kubernetes.io/canary: "true"
nginx.ingress.kubernetes.io/canary-by-header: "authtype"
nginx.ingress.kubernetes.io/canary-by-header-value: "myjwt"
spec:
ingressClassName: nginx
rules:
- host: something.com
http:
paths:
- pathType: Prefix
path: /i
backend:
service:
name: asvc
port:
number: 8000