Skip to content

Instantly share code, notes, and snippets.

@pleshakov
Created September 19, 2023 22:24
Show Gist options
  • Save pleshakov/9e890e359ee47c4be908f13590ee9377 to your computer and use it in GitHub Desktop.
Save pleshakov/9e890e359ee47c4be908f13590ee9377 to your computer and use it in GitHub Desktop.
Gateway API HTTP example listener matching

Steps:

kubectl apply -f cafe.yaml
kubectl apply -f gateway.yaml
kubectl apply -f routes.yaml

GW_IP=XXX.YYY.ZZZ.III # public IP of the data plane
GW_PORT=<port number> # public port

curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee
curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/tea
apiVersion: apps/v1
kind: Deployment
metadata:
name: coffee
spec:
replicas: 1
selector:
matchLabels:
app: coffee
template:
metadata:
labels:
app: coffee
spec:
containers:
- name: coffee
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: coffee
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: coffee
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tea
spec:
replicas: 1
selector:
matchLabels:
app: tea
template:
metadata:
labels:
app: tea
spec:
containers:
- name: tea
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: tea
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: tea
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: gateway
spec:
gatewayClassName: gke-l7-global-external-managed
# gatewayClassName: eg
# gatewayClassName: nginx
# gatewayClassName: contour
listeners:
- name: example
port: 80
hostname: "*.example.com"
protocol: HTTP
- name: cafe
port: 80
protocol: HTTP
hostname: "cafe.example.com"
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: coffee
spec:
parentRefs:
- name: gateway
sectionName: example
hostnames:
- "cafe.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /coffee
backendRefs:
- name: coffee
port: 80
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: tea
spec:
parentRefs:
- name: gateway
sectionName: cafe
hostnames:
- "*.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /tea
backendRefs:
- name: tea
port: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment