https://gateway-api.sigs.k8s.io/reference/spec/#gateway.networking.k8s.io%2fv1.HTTPHeaderMatch
# vim nginx-gateway.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: nginx-gateway
namespace: nginx-gateway
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP
allowedRoutes:
namespaces:
from: All
k apply -f nginx-gateway.yaml
# vim restricted.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: restricted
namespace: app
spec:
parentRefs:
- name: nginx-gateway
namespace: nginx-gateway
sectionName: http
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: app-restricted
port: 80
k apply -f restricted.yaml
#vim cka-route.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: cka-route
namespace: app
spec:
hostnames:
- cka.local
parentRefs:
- name: nginx-gateway
namespace: nginx-gateway
sectionName: http
rules:
- matches:
- path:
type: PathPrefix
value: /
headers:
- name: environment
value: dev
backendRefs:
- name: app-dev
port: 80
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: app-prod
port: 80
k apply -f cka-route.yaml
# vim dev-cka-route.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: dev-cka-route
namespace: app
spec:
hostnames:
- dev-cka.local
parentRefs:
- name: nginx-gateway
namespace: nginx-gateway
sectionName: http
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: app-dev
port: 80
k apply -f dev-cka-route.yaml
# vim weight-cka-route.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: weight-cka-route
namespace: app
spec:
hostnames:
- weight-cka.local
parentRefs:
- name: nginx-gateway
namespace: nginx-gateway
sectionName: http
rules:
- matches:
- path:
type: PathPrefix
value: /
backendRefs:
- name: app-weight-v1
port: 80
weight: 70
- name: app-weight-v2
port: 80
weight: 30
k apply -f weight-cka-route.yaml
# vim header-cka-route.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: header-cka-route
namespace: app
spec:
hostnames:
- header-cka.local
parentRefs:
- name: nginx-gateway
namespace: nginx-gateway
sectionName: http
rules:
- matches:
- path:
type: PathPrefix
value: /
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
add:
- name: User-Type
value: test-user
remove:
- X-CH
set:
- name: User-City
value: NYC
backendRefs:
- name: app-dev
port: 80
k apply -f header-cka-route.yaml