Route to external services
Enable services in your service mesh to route to endpoints that are located outside the service mesh.
In some cases, one of your Istio-managed apps might need to communicate with services that are external to the service mesh. For example, your app might need to contact a public API or an on-prem database. If you installed Istio with the REGISTRY_ONLY
option, communication is allowed only between services in the mesh. Communication to services outside the mesh is prohibited. To allow services in the mesh to talk to services outside the mesh, you can leverage Gloo ExternalService
and ExternalEndpoint
custom resources. Gloo Mesh translates these resources into an Istio ServiceEntry.
In this guide, you can choose between two solutions to allow routing to an external service, allow routing to an IP address, CIDR, or hostname directly and configure an internal DNS entry to group multiple external endpoints behind one common IP address or hostname. The solution that is right for you depends on your use case. Make sure to review the Routing to external services concept doc for more information.
For additional information about the Gloo custom resources, see the following resources:
- Gloo Mesh Enterprise API docs for ExternalEndpoint
- Gloo Mesh Enterprise API docs for ExternalService
Before you begin
This guide assumes that you use the same names for components like clusters, workspaces, and namespaces as in the getting started. If you have different names, make sure to update the sample configuration files in this guide.
Complete the multicluster getting started guide to set up the following testing environment.
- Three clusters along with environment variables for the clusters and their Kubernetes contexts.
- The Gloo
meshctl
CLI, along with other CLI tools such askubectl
andistioctl
. - The Gloo management server in the management cluster, and the Gloo agents in the workload clusters.
- Istio installed in the workload clusters.
- A simple Gloo workspace setup.
- Install Bookinfo and other sample apps.
Decide on the approach to allow routing to an external service. You can choose between the following options:
The guides on this page use a simple route table to allow routing to an external service. For additional route table options, check out the path matching guide to decide how to match the incoming requests to your service paths, the redirect guide to set up any path or host rewrites, or the sub-table delegation guide to nest and sort multiple route tables. Note: Be sure that each route for one host is unique, such as by using prefix matching to determine which requests to the host should be forwarded to which destinations.
Allow routing to an IP address, CIDR, or hostname directly
You can allow routing to an external static IP address, CIDR range, or hostname from services in your mesh by using an ExternalService
Gloo custom resource.
If you use a wildcard prefix domain for the external service host without selecting any ExternalEndpoints
, the REGISTRY_ONLY
outbound traffic policy can be bypassed and traffic can be sent to any external service by using a TCP passthrough listener on the sidecar proxy. Consider creating an internal DNS entry by using an ExternalEndpoint
for these cases. You can use the instructions in Create internal DNS entries for multiple external endpoints as a guidance for how to set up ExternalService
and ExternalEndpoint
resources.
Get the addresses and ports that your external resources listen on. For example, the address might be a static IP address, a CIDR range, or a registered hostname.
Create an external service resource with either the
addresses
orhostname
option. Note that you cannot specify a hostname and an IP address or CIDR in the same external service resource.Create a route table to allow routing to the external service.
kubectl apply --context $REMOTE_CONTEXT1 -n global -f- <<EOF apiVersion: networking.gloo.solo.io/v2 kind: RouteTable metadata: name: db-routes namespace: global spec: hosts: - '*' http: # Route for the db-external-service - name: db-app # Prefix matching matchers: - uri: prefix: /db/ # Forwarding directive forwardTo: destinations: # Reference to the external service resource exposing your external endpoints - ref: name: db-external-service cluster: ${REMOTE_CLUSTER1} kind: EXTERNAL_SERVICE pathRewrite: / EOF
Test the route to your external resource from one of the apps in your service mesh. For example, log in to an initiator app in your mesh and run
nslookup my-remote-db.com/db
orcurl 123.221.3.0:80/db
to verify that the external resource is reachable.
Create internal DNS entries for multiple external endpoints
Instead of allowing specific IP addresses, CIDR ranges, or hostnames directly, you can set up an internal hostname or IP address that serves multiple external endpoints and therefore works similarly to setting up a CNAME or A record in your DNS provider. To do that, you use ExternalEndpoint
custom resources to define the external endpoints. Then, you define the internal hostname or IP address that services in the mesh use to route traffic to any of these endpoints in the ExternalService
resource.
Get the address and ports that your external resource listens on. For example, the address might be a static IP address or a registered URL.
Create an external endpoint for each address and an external service. The external endpoint represents the server or service outside of your service mesh that you want to reach. By using a Gloo Mesh external service, you can then assign a unique hostname to this external endpoint that services in your mesh can use to send requests. You can also use this service to route incoming requests from your ingress gateway directly to your external endpoint.
Create a route table to route requests to the external service.
Test the route to your external resource from one of the apps in your service mesh. For example, log in to an initiator app in your mesh and run
nslookup my-remote-db.com/db
ornslookup my-remote-svc.com/httpbin
to verify that the external resource is reachable through the external service hostname. Or, if you can access an app in your service mesh externally, you can curl the ingress gateway address and the path for your initiator app, and verify that information from the external resource is being successfully returned.
Next steps
- If you haven’t already, follow the other guides in the routing section to plan your routing table setup. For example, you might check out the prefix matching guide to decide how to match the incoming requests to your service paths, the redirect guide to set up any path or prefix rewrites, or the sub-table delegation guide to nest and sort multiple route tables.
- Configure additional route settings, such as weighted routing to version subsets or adding and removing headers.
- Apply a traffic policy to your service or route. For example, you might set a connection policy to keep alive connections that the load balancer in your infrastructure provider might otherwise periodically close.