Layer 7 routing in Service Mesh (ASM) routes traffic based on URI paths and request headers. Before you configure routing rules, set up your ASM environment and deploy the sample applications that your use case requires.
This topic covers two steps:
Meet the prerequisites: create an ASM instance, add a cluster, and enable sidecar proxy injection.
Deploy sample applications: deploy the services that your Layer 7 routing use case depends on.
Prerequisites
Before you begin, make sure you have:
An ASM instance of Enterprise Edition. See Create an ASM instance
ImportantIn the Dataplane Mode section of the Create Service Mesh page, do not select Enable Ambient Mesh mode. Layer 7 routing with sidecar proxies is not compatible with ambient mesh mode.
A Container Service for Kubernetes (ACK) cluster. See Create an ACK dedicated cluster or Create an ACK managed cluster
Automatic sidecar proxy injection enabled for the
defaultnamespace. See the "Enable automatic sidecar proxy injection" section in Manage global namespaces
Deploy sample applications
Deploy one or more of the following services in your ACK cluster, depending on which Layer 7 routing use case you plan to configure.
| Service | Port | Use case |
|---|---|---|
| helloworld | 5000 | Version-based routing (v1/v2 traffic splitting) |
| sleep | 80 | Client pod for sending test requests to other services |
| HTTPBin | 8000 | Header and path matching |
| NGINX | 8000 | Basic HTTP routing and load balancing |
All deployment commands below assume kubectl is configured to connect to your ACK cluster through the kubeconfig file.
Deploy the helloworld service
The helloworld service runs two versions (v1 and v2), which makes it suitable for testing version-based routing rules.
Save the following YAML to a file named
helloworld-application.yaml:Apply the manifest:
kubectl apply -f helloworld-application.yamlVerify that the pods are running with sidecar proxies injected (the READY column shows
2/2): Expected output:kubectl get pods -l app=helloworldNAME READY STATUS RESTARTS AGE helloworld-v1-xxxxxxxxx-xxxxx 2/2 Running 0 30s helloworld-v2-xxxxxxxxx-xxxxx 2/2 Running 0 30s
Deploy the sleep service
The sleep service provides a curl-enabled pod for sending test requests to other services in the mesh.
Save the following YAML to a file named
sleep-application.yaml:Apply the manifest:
kubectl apply -f sleep-application.yamlVerify that the sleep pod is running with its sidecar proxy: Expected output:
kubectl get pods -l app=sleepNAME READY STATUS RESTARTS AGE sleep-xxxxxxxxx-xxxxx 2/2 Running 0 30s
Deploy the HTTPBin service
HTTPBin returns structured HTTP response data, which makes it useful for testing header matching and path-based routing.
Save the following YAML to a file named
httpbin-application.yaml:Apply the manifest:
kubectl apply -f httpbin-application.yamlVerify that the HTTPBin pod is running: Expected output:
kubectl get pods -l app=httpbinNAME READY STATUS RESTARTS AGE httpbin-xxxxxxxxx-xxxxx 2/2 Running 0 30s
Deploy the NGINX service
NGINX serves as a basic HTTP backend for testing standard routing and load balancing rules.
Save the following YAML to a file named
nginx.yaml:Apply the manifest:
kubectl apply -f nginx.yamlVerify that the NGINX pod is running: Expected output:
kubectl get pods -l app=nginxNAME READY STATUS RESTARTS AGE nginx-xxxxxxxxx-xxxxx 2/2 Running 0 30s
Confirm service registration
After deploying the sample applications, confirm that the services are registered in the cluster:
kubectl get servicesMake sure each deployed service appears in the output with the expected port.
What to do next
After you complete these preparations, proceed to the Layer 7 routing use case for your scenario. Each use case specifies which sample applications it requires.