Skip to content

Commit 89d63b0

Browse files
authored
Merge pull request #95506 from rh-tokeefe/OSSM-9884A
OSSM-9884: Create egress gateway using gateway API
2 parents 9f25265 + 109ed5c commit 89d63b0

File tree

2 files changed

+207
-1
lines changed

2 files changed

+207
-1
lines changed

gateways/ossm-directing-outbound-traffic.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ toc::[]
99
Using {istio} APIs, you can configure gateway proxies that were installed using gateway injection to direct traffic that is bound for an external service.
1010

1111
include::modules/ossm-about-directing-egress-traffic-through-a-gateway.adoc[leveloffset=+1]
12-
include::modules/ossm-directing-egress-traffic-through-a-gateway-using-istio-apis.adoc[leveloffset=+1]
12+
include::modules/ossm-directing-egress-traffic-through-a-gateway-using-istio-apis.adoc[leveloffset=+1]
13+
include::modules/ossm-directing-egress-traffic-through-a-gateway-using-kubernetes-gateway-api.adoc[leveloffset=+1]
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
// This procedure is used in the following assembly:
2+
// * service-mesh-docs-main/gateways/ossm-directing-outbound-traffic-through-a-gateway
3+
4+
:_mod-docs-content-type: PROCEDURE
5+
[id="ossm-directing-egress-traffic-through-a-gateway-using-kubernetes-gateway-api_{context}"]
6+
= Directing egress traffic through a gateway by using the {k8s} Gateway API
7+
8+
Use the {k8s} Gateway API to direct outbound HTTP traffic through an egress gateway.
9+
10+
.Prerequisites
11+
12+
* You installed an {istio} control plane.
13+
14+
* You configured the `Istio` and `IstioCNI` resources.
15+
16+
.Procedure
17+
18+
. Optional: Enable the {k8} Gateway API custom resource definitions (CRDs).
19+
+
20+
[NOTE]
21+
====
22+
As of {k8s} 1.28 and {ocp-product-title} 4.18 or earlier version of {product-title}, the {k8s} Gateway API CRDs are not available by default and you must enabled the CRDs before you can use them. {ocp-product-title} 4.19 and later versions enable the CRDs by default.
23+
====
24+
25+
.. Create a YAML file named `gateway-cr.yaml` that enables the Kubernetes Gateway API CRDs.
26+
+
27+
.Example {k8s} Gateway Custom Resource (CR) file
28+
[source,yaml,subs="attributes,verbatim"]
29+
----
30+
apiVersion: gateway.networking.k8s.io/v1
31+
kind: Gateway
32+
metadata:
33+
name: bookinfo-gateway
34+
spec:
35+
gatewayClassName: istio
36+
listeners:
37+
- name: http
38+
port: 80
39+
protocol: HTTP
40+
allowedRoutes:
41+
namespaces:
42+
from: Same
43+
---
44+
apiVersion: gateway.networking.k8s.io/v1
45+
kind: HTTPRoute
46+
metadata:
47+
name: bookinfo
48+
spec:
49+
parentRefs:
50+
- name: bookinfo-gateway
51+
rules:
52+
- matches:
53+
- path:
54+
type: Exact
55+
value: /productpage
56+
- path:
57+
type: PathPrefix
58+
value: /static
59+
- path:
60+
type: Exact
61+
value: /login
62+
- path:
63+
type: Exact
64+
value: /logout
65+
- path:
66+
type: PathPrefix
67+
value: /api/v1/products
68+
backendRefs:
69+
- name: productpage
70+
port: 9080
71+
----
72+
73+
.. Apply the YAML file by running the following command:
74+
+
75+
[source,terminal]
76+
----
77+
$ oc apply -f gateway-cr.yaml
78+
----
79+
80+
. Create a namespace called `egress-gateway` by running the following command:
81+
+
82+
[source,terminal]
83+
----
84+
$ oc create namespace egress-gateway
85+
----
86+
87+
. Apply the `istio-injection` label to the namespace by running the following command:
88+
+
89+
[source,terminal]
90+
----
91+
$ oc label namespace egress-gateway istio-injection=enabled
92+
----
93+
94+
. Create a YAML file named `egress-gateway-cr.yaml` that defines the egress gateway.
95+
+
96+
.Example egress gateway CR file
97+
[source,yaml,subs="attributes,verbatim"]
98+
----
99+
# ServiceEntry to allow traffic to httpbin.org
100+
apiVersion: networking.istio.io/v1
101+
kind: ServiceEntry
102+
metadata:
103+
name: httpbin-ext
104+
spec:
105+
hosts:
106+
- httpbin.org
107+
ports:
108+
- number: 80
109+
name: http
110+
protocol: HTTP
111+
location: MESH_EXTERNAL
112+
resolution: DNS
113+
---
114+
# Gateway API Gateway for egress
115+
apiVersion: gateway.networking.k8s.io/v1
116+
kind: Gateway
117+
metadata:
118+
name: httpbin-egress-gateway
119+
annotations:
120+
networking.istio.io/service-type: ClusterIP
121+
spec:
122+
gatewayClassName: istio
123+
listeners:
124+
- name: http
125+
hostname: httpbin.org
126+
port: 80
127+
protocol: HTTP
128+
allowedRoutes:
129+
namespaces:
130+
from: Same
131+
---
132+
# HTTPRoute to direct traffic from sidecars to the egress gateway
133+
apiVersion: gateway.networking.k8s.io/v1
134+
kind: HTTPRoute
135+
metadata:
136+
name: direct-httpbin-to-egress-gateway
137+
spec:
138+
parentRefs:
139+
- kind: ServiceEntry
140+
group: networking.istio.io
141+
name: httpbin-ext
142+
rules:
143+
- backendRefs:
144+
- name: httpbin-egress-gateway-istio
145+
port: 80
146+
---
147+
# HTTPRoute to forward traffic from the egress gateway to httpbin.org
148+
apiVersion: gateway.networking.k8s.io/v1
149+
kind: HTTPRoute
150+
metadata:
151+
name: forward-httpbin-from-egress-gateway
152+
spec:
153+
parentRefs:
154+
- name: httpbin-egress-gateway
155+
hostnames:
156+
- httpbin.org
157+
rules:
158+
- backendRefs:
159+
- kind: Hostname
160+
group: networking.istio.io
161+
name: httpbin.org
162+
port: 80
163+
----
164+
165+
.. Apply the YAML file by running the following command:
166+
+
167+
[source,terminal]
168+
----
169+
$ oc apply -f egress-gateway-cr.yaml
170+
----
171+
172+
.Verification
173+
174+
. Verify the status of the gateway configuration by running the following command:
175+
+
176+
[source,terminal]
177+
----
178+
$ oc describe gateway -n egress-gateway
179+
----
180+
+
181+
Desired output is indicated by `Programmed` showing in the `Status` column.
182+
183+
. Create a `curl` pod in the `egress-gateway` namespace by running the following command:
184+
+
185+
[source,terminal]
186+
----
187+
$ oc run test-pod --image=curlimages/curl:latest -n egress-gateway --rm -it --restart=Never -- sh
188+
----
189+
190+
. By using the `curl` client, verify that you can access `httpbin.org` through the egress gateway by entering following command:
191+
+
192+
[source,terminal]
193+
----
194+
$ curl -v http://httpbin.org/get
195+
----
196+
+
197+
Desired output shows a response from `httpbin.org` that indicates egress traffic routes through the configured gateway.
198+
199+
[role="_additional-resources-egress"]
200+
.Additional resources
201+
202+
* link:https://istio.io/latest/docs/tasks/traffic-management/egress/egress-gateway/[Egress gateways] (Istio documentation)
203+
204+
* link:https://gateway-api.sigs.k8s.io/[Introduction] (Gateway API documentation)
205+

0 commit comments

Comments
 (0)