Routing egress traffic via a gateway with Istio APIs
This section explains how to use Istio APIs to route outbound HTTP traffic via a gateway installed with gateway injection.
TOC
Prerequisites
- An Istio gateway has been installed using gateway injection.
Procedure
-
Create a namespace named
curlby executing the following command: -
Enable sidecar injection for the namespace. If your setup uses the
InPlaceupgrade strategy, run this command:NOTEIf you are using the
RevisionBasedupgrade strategy, execute these commands:-
To discover your
<revision-name>, run the following:Sample output:
-
Label the namespace using the revision name to enable sidecar injection:
-
-
Deploy the
curlapplication by running this command: -
Initialize and export a
CURL_PODenvironment variable containing the name of the curl pod: -
Create a YAML file with the name
http-se.yamlto direct traffic from the mesh toward an external service. The example below defines aServiceEntryfor a specific URL.Example configuration
-
Apply this YAML file by executing the command:
-
Confirm that the
ServiceEntryconfiguration has been applied successfully. Send an HTTP request to the host specified in the previous step by running this command:This command should yield HTTP status codes like
302(redirect) or200(success), which confirms the connection is working. -
Create a YAML file named
http-egress-gw.yamlthat establishes an egressGatewayand routes traffic from the mesh to the host defined for the external service.Example configuration
-
Apply the YAML file by executing the command:
-
Create a YAML file with the name
http-egress-vs.yamlto configure aVirtualServicethat will manage traffic flow from application sidecars, through the egress gateway, and to the external host.Example configuration
-
Apply this YAML file by running the following command:
-
Reissue the HTTP request to the URL:
The terminal output should be similar to what is shown below:
Example output
-
Confirm that the request was routed via the gateway by running this command:
Enable access loggingAccess logging must be active for this verification step to function correctly. You can enable it by creating the following
Telemetryresource.Your terminal should display information similar to this output:
Example output