Add apps to the service mesh
Add services in existing namepaces to your service mesh, or deploy the Bookinfo sample app to try out traffic routing in your service mesh.
Add services to the mesh
Now that Istio is up and running, you can create service namespaces for your teams to run app workloads in. For any namespaces that you want to deploy apps to, be sure to follow these steps to include your services in the service mesh.
Save the revision that you used for your istiod installation in an environment variable. Typically, this is
main
for a Helm installation, orgloo
for a Gloo operator installation.- Gloo operator:
- Helm:
- Gloo operator:
Label the service namespace for Istio sidecar injection with the revision label.
If you already deployed app pods to the namespace, restart the workloads so that sidecars are injected into the pods. For example, you might roll out a restart to each deployment by using a command similar to the following.
Make services available across clusters
If you linked clusters to form a multicluster ambient or sidecar mesh, you can make a service available across clusters throughout the multicluster mesh by using the solo.io/service-scope=global
service label. When you apply this label to a service, it does not change the service. Instead, a new global service is created with a hostname in the format <name>.<namespace>.mesh.internal
.
You can then use this internal hostname for in-mesh routing. For example, you might create a Gateway resource in cluster1 to manage incoming traffic requests for your app in cluster2. To make the app accessible across clusters, you label its service with solo.io/service-scope=global
, which generates a global service hostname. To route requests to the app, you create an HTTPRoute resource that references this global service hostname. The ingress gateway can then use this global service hostname in the HTTPRoute to route incoming traffic requests through the east-west gateway across clusters to your app.
For the service that you want to be accessible from multiple clusters, apply the
solo.io/service-scope=global
label.Verify that the global service entry with a hostname in the format
<svc_name>.<namespace>.mesh.internal
is created in theistio-system
namespace. This hostname makes the endpoint for your service available across the multicluster mesh.Example output:
If you have a service of the same name and namespace in another cluster of the mesh, label that service too. This way, the service’s endpoint is added to the global service’s hostname, and increases the availability of your service in the multicluster mesh. For more information, see Namespace sameness.
Optional: Modify the way that traffic is routed to service endpoints for the global service by applying the
networking.istio.io/traffic-distribution
annotation to each service instance. For more information, see Endpoint traffic control.
For an example of deploying an app to a multicluster mesh, see Bookinfo example: Multicluster.
Namespace sameness
You might have the same app service in the same namespace in multiple clusters. When you label the service in one cluster, a global service is created in the mesh for that service’s endpoint. However, you must also label the service in the other cluster to include its endpoint in the global service’s hostname. When you label each service, then all instances of that app in the multicluster mesh are exposed by the global service. By adhering to the principle of namespace sameness, the global service’s hostname unifies the endpoints for each service across the clusters.
For example, you might have a myapp
service in the stage
namespace of cluster1
, and a myapp
service in the stage
namespace of cluster2
. If you label the service in cluster1
with solo.io/service-scope=global
, a global service is created with the hostname myapp.stage.mesh.internal
. However, until you label the service in cluster2
, the service is not automatically included in the global service’s endpoints.
Endpoint traffic control
If an in-mesh service makes a request to a service that is exposed globally, and a healthy endpoint for that service is available locally in the same cluster network, the request is routed to that local instance by default. If no healthy endpoints of that service are available locally, requests are routed to healthy endpoints in remote cluster networks. An endpoint is considered healthy if the app pod exposed by that local service is in a ready state.
To modify this default behavior for global services, you can apply the networking.istio.io/traffic-distribution
annotation to a service that has the solo.io/service-scope=global
label.
PreferNetwork
: Route requests to available endpoints within the source’s same network first. This is the default for global services.PreferClose
: Route requests to an available endpoint that is closest to the source first, considering the zone, region, and network. For example, you might have a global service with two endpoints in zoneus-west
and one endpoint inus-east
. When sending traffic from a client inus-west
, all traffic routes to the twous-west
endpoints. If one of those endpoints becomes unhealthy, all traffic routes to the remaining endpoint inus-west
. If that endpoint becomes unhealthy, traffic routes to theus-east
endpoint.PreferRegion
: Route requests to an available endpoint that is closest to the source first, considering the region and network.Any
: Consider all endpoints equally, and route requests to a random available endpoint.
Recall that the directionality that you choose when you link the clusters can also affect how services can communicate. For example, if you choose to asymmetrically link your clusters, services in one cluster might not be able to send requests to remote endpoints for services in another cluster.
Subset routing
Traditional subset routing in Istio, such by configuring routing rules to different app subsets in a DestinationRule, is currently not supported for cross-cluster routing when using multicluster peering. Instead, the recommended approach involves using services to represent specific subsets, and using an HTTPRoute resource to manage cross-cluster routing to each “subset” service.
For example, say that you have three clusters that you linked together to create a multicluster mesh.
- You deploy the Bookinfo app across the clusters by creating the ratings and productpage microservices in
cluster0
, reviews-v1 incluster1
, and reviews-v2 incluster2
. - You then abstract the reviews subsets into individual services, such as one service called
reviews-v1
and one service calledreviews-v2
, instead of using just onereviews
service for both. - To ensure that each service is accessible across the multicluster mesh, you label them with
solo.io/service-scope=global
, so that they now have internal global hostnames such asreviews-v1.bookinfo.internal.mesh
andreviews-v2.bookinfo.internal.mesh
. - To manage routing rules for each service, you create an HTTPRoute similar to the following example. This HTTPRoute routes requests to each global service hostname. You can then implement routing rules to each “subset” service, such as by using header matching to send requests from a user called “blackstar” to only reviews-v2.
Bookinfo example: Single cluster
Save the revision that you used for your istiod installation in an environment variable. Typically, this is
main
for a Helm installation, orgloo
for a Gloo operator installation.- Gloo operator:
- Helm:
- Gloo operator:
Create the
bookinfo
namespace and label it so that the services become part of the service mesh.Deploy the Bookinfo app.
Verify that the Bookinfo app deployed successfully.
Bookinfo example: Multicluster
For testing purposes, you can deploy the Bookinfo sample app across multiple clusters, add the app services to your sidecar mesh, and make the services available across clusters in the mesh.
Deploy Bookinfo
Save the kubeconfig contexts for two clusters that you deployed an a sidecar mesh to and linked together.
Save the revision that you used for your istiod installation in an environment variable. Typically, this is
main
for a Helm installation, orgloo
for a Gloo operator installation.- Gloo operator:
- Helm:
- Gloo operator:
Create the
bookinfo
namespace in each cluster, and label them with theistio.io/rev=$REVISION
label. This label adds all Bookinfo services that you create in each namespace to the sidecar mesh in the respective cluster.Deploy Bookinfo with the
details
,productpage
,ratings
,reviews-v1
, andreviews-v2
services in the first cluster.Deploy Bookinfo with the
ratings
andreviews-v3
services in the second cluster.Verify that the Bookinfo app is deployed successfully.
Expose services across clusters
To make Bookinfo globally available in the multicluster setup, you label each productpage
service so that both productpage
endpoints are available behind one global service hostname.
Label the
productpage
service in each cluster to create oneproductpage
global service.Apply the
networking.istio.io/traffic-distribution=Any
annotation to the services. This annotation allows requests to theproductpage
global service to be routed to each service endpoint equally.Verify that the global service entry with the
productpage.bookinfo.mesh.internal
hostname is created in theistio-system
namespace.Example output:
Use the ratings app to send a request to the
productpage.bookinfo.mesh.internal
global hostname. Verify that you get back a 200 HTTP response code.Example output:
The
productpage
services for each Bookinfo instance are now unified behind one hostname, which increases the availability of the Bookinfo app. You can now use this global service hostname in routing configurations. For example, to expose theproductpage
global service hostname with an ingress gateway, continue with the Bookinfo example in the ingress gateway guide.Scale down the productpage app in
$REMOTE_CLUSTER1
.Repeat the request from the ratings app to the productpage app. Because the productpage app in
$REMOTE_CLUSTER1
is unavailable, all traffic is automatically routed to the productpage app in$REMOTE_CLUSTER2
through the east-west gateway. Verify that you get back a 200 HTTP response code.Example output:
If you also installed Gloo Mesh, open the Gloo UI. If you do not have Gloo Mesh installed, you can follow the Get started guide.
Navigate to Observability > Graph and verify that you see the traffic flow for your multicluster setup. Note that you might need to select both clusters and the
bookinfo
andistio-eastwest
namespaces.Scale the productpage deployment back up in $REMOTE_CLUSTER1.
Next
- Expose apps in your mesh with an ingress gateway.
- Launch the Gloo UI to review the Istio insights that were captured for your service mesh setup. Gloo Mesh comes with an insights engine that automatically analyzes your Istio setups for health issues. These issues are displayed in the UI along with recommendations to harden your Istio setups. The insights give you a checklist to address issues that might otherwise be hard to detect across your environment. For more information, see Insights.
- When it’s time to upgrade your service mesh, you can perform a safe in-place upgrade by using the Gloo operator or Helm.