Skip to content

Commit e3b3349

Browse files
committed
examples: add gateway-api
Adds an example using the new gateway-api (backed by cilium), similar to the ingress example. Cilium is used because our test cluster (k8test) already installs cilium.
1 parent 56770d2 commit e3b3349

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

examples/gateway-api.yaml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Deploys two docker.io/nginxdemos/hello:plain-text containers ("blue" and "red")
2+
# and creates ClusterIP services named "blue-svc" and "red-svc" for the
3+
# deployments.
4+
# Additionally:
5+
# - a Gateway resource named "my-gateway" using Cilium Gateway-API is set up
6+
# - a HTTPRoute named "simple" using "my-gateway" is used to route requests for "/red" to "red-svc" service and
7+
# requests for "/blue" to the "blue-svc" service.
8+
#
9+
# This examples needs cilium with Gateway-API support to be installed, see:
10+
# https://docs.cilium.io/en/stable/network/servicemesh/gateway-api/gateway-api/#gs-gateway-api
11+
# https://gateway-api.sigs.k8s.io/guides/
12+
#
13+
# Setup using k8test (https://github.com/cloudscale-ch/k8test):
14+
# $ export KUBECONFIG=k8test/cluster/admin.conf
15+
# $ kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.4.1/experimental-install.yaml
16+
# $ cilium upgrade --set kubeProxyReplacement=true --set gatewayAPI.enabled=true
17+
# $ kubectl apply -f examples/gateway-api.yaml
18+
#
19+
# Wait for `kubectl get gateway my-gateway` to
20+
# show "PROGRAMMED: True", then use the IP address found under "ADDRESS" to connect to the service.
21+
#
22+
# You can also use the following shortcut:
23+
#
24+
# curl http://$(kubectl get gateway my-gateway -o jsonpath='{.status.addresses[0].value}')/blue
25+
# curl http://$(kubectl get gateway my-gateway -o jsonpath='{.status.addresses[0].value}')/red
26+
#
27+
---
28+
apiVersion: apps/v1
29+
kind: Deployment
30+
metadata:
31+
labels:
32+
app: blue
33+
name: blue
34+
spec:
35+
replicas: 1
36+
selector:
37+
matchLabels:
38+
app: blue
39+
template:
40+
metadata:
41+
labels:
42+
app: blue
43+
spec:
44+
containers:
45+
- image: docker.io/nginxdemos/hello:plain-text
46+
name: hello
47+
---
48+
apiVersion: v1
49+
kind: Service
50+
metadata:
51+
labels:
52+
app: blue
53+
name: blue-svc
54+
spec:
55+
ports:
56+
- port: 80
57+
protocol: TCP
58+
targetPort: 80
59+
selector:
60+
app: blue
61+
---
62+
apiVersion: apps/v1
63+
kind: Deployment
64+
metadata:
65+
labels:
66+
app: red
67+
name: red
68+
spec:
69+
replicas: 1
70+
selector:
71+
matchLabels:
72+
app: red
73+
template:
74+
metadata:
75+
labels:
76+
app: red
77+
spec:
78+
containers:
79+
- image: docker.io/nginxdemos/hello:plain-text
80+
name: hello
81+
resources: { }
82+
---
83+
apiVersion: v1
84+
kind: Service
85+
metadata:
86+
labels:
87+
app: red
88+
name: red-svc
89+
spec:
90+
ports:
91+
- port: 80
92+
protocol: TCP
93+
targetPort: 80
94+
selector:
95+
app: red
96+
---
97+
apiVersion: gateway.networking.k8s.io/v1
98+
kind: Gateway
99+
metadata:
100+
name: my-gateway
101+
spec:
102+
gatewayClassName: cilium
103+
listeners:
104+
- protocol: HTTP
105+
port: 80
106+
name: web-gw
107+
allowedRoutes:
108+
namespaces:
109+
from: Same
110+
---
111+
apiVersion: gateway.networking.k8s.io/v1
112+
kind: HTTPRoute
113+
metadata:
114+
name: simple
115+
spec:
116+
parentRefs:
117+
- name: my-gateway
118+
rules:
119+
- matches:
120+
- path:
121+
type: Exact
122+
value: /red
123+
backendRefs:
124+
- name: red-svc
125+
port: 80
126+
- matches:
127+
- path:
128+
type: Exact
129+
value: /blue
130+
backendRefs:
131+
- name: blue-svc
132+
port: 80

0 commit comments

Comments
 (0)