All Products
Search
Document Center

Alibaba Cloud Service Mesh:Preparations for Layer 7 routing

Last Updated:Mar 11, 2026

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:

  1. Meet the prerequisites: create an ASM instance, add a cluster, and enable sidecar proxy injection.

  2. Deploy sample applications: deploy the services that your Layer 7 routing use case depends on.

Prerequisites

Before you begin, make sure you have:

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.

ServicePortUse case
helloworld5000Version-based routing (v1/v2 traffic splitting)
sleep80Client pod for sending test requests to other services
HTTPBin8000Header and path matching
NGINX8000Basic 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.

  1. Save the following YAML to a file named helloworld-application.yaml:

    helloworld-application.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: helloworld
      labels:
        app: helloworld
    spec:
      ports:
      - port: 5000
        name: http
      selector:
        app: helloworld
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: helloworld
      labels:
        account: helloworld
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: helloworld-v1
      labels:
        apps: helloworld
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: helloworld
          version: v1
      template:
        metadata:
          labels:
            app: helloworld
            version: v1
        spec:
          serviceAccount: helloworld
          serviceAccountName: helloworld
          containers:
          - name: helloworld
            image: istio/examples-helloworld-v1
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 5000
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: helloworld-v2
      labels:
        apps: helloworld
        version: v2
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: helloworld
          version: v2
      template:
        metadata:
          labels:
            app: helloworld
            version: v2
        spec:
          serviceAccount: helloworld
          serviceAccountName: helloworld
          containers:
          - name: helloworld
            image: istio/examples-helloworld-v2
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 5000
  2. Apply the manifest:

       kubectl apply -f helloworld-application.yaml
  3. Verify that the pods are running with sidecar proxies injected (the READY column shows 2/2): Expected output:

       kubectl get pods -l app=helloworld
       NAME                              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.

  1. Save the following YAML to a file named sleep-application.yaml:

    sleep-application.yaml

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: sleep
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: sleep
      labels:
        app: sleep
        service: sleep
    spec:
      ports:
      - port: 80
        name: http
      selector:
        app: sleep
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: sleep
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: sleep
      template:
        metadata:
          labels:
            app: sleep
        spec:
          terminationGracePeriodSeconds: 0
          serviceAccountName: sleep
          containers:
          - name: sleep
            image: curlimages/curl
            command: ["/bin/sleep", "3650d"]
            imagePullPolicy: IfNotPresent
            volumeMounts:
            - mountPath: /etc/sleep/tls
              name: secret-volume
          volumes:
          - name: secret-volume
            secret:
              secretName: sleep-secret
              optional: true
  2. Apply the manifest:

       kubectl apply -f sleep-application.yaml
  3. Verify that the sleep pod is running with its sidecar proxy: Expected output:

       kubectl get pods -l app=sleep
       NAME                     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.

  1. Save the following YAML to a file named httpbin-application.yaml:

    httpbin-application.yaml

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: httpbin
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: httpbin
      labels:
        app: httpbin
        service: httpbin
    spec:
      ports:
      - name: http
        port: 8000
        targetPort: 80
      selector:
        app: httpbin
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: httpbin
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: httpbin
          version: v1
      template:
        metadata:
          labels:
            app: httpbin
            version: v1
        spec:
          serviceAccountName: httpbin
          containers:
          - image: docker.io/kennethreitz/httpbin
            imagePullPolicy: IfNotPresent
            name: httpbin
            ports:
            - containerPort: 80
  2. Apply the manifest:

       kubectl apply -f httpbin-application.yaml
  3. Verify that the HTTPBin pod is running: Expected output:

       kubectl get pods -l app=httpbin
       NAME                       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.

  1. Save the following YAML to a file named nginx.yaml:

    nginx.yaml

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: nginx
    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: nginx
        service: nginx
      name: nginx
    spec:
      ports:
        - name: http
          port: 8000
          protocol: TCP
          targetPort: 80
      selector:
        app: nginx
      type: ClusterIP
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: nginx
        version: v1
      name: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
          version: v1
      template:
        metadata:
          labels:
            app: nginx
            version: v1
        spec:
          serviceAccountName: nginx
          containers:
            - image: 'nginx:1.7.9'
              name: nginx
              ports:
                - containerPort: 80
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
  2. Apply the manifest:

       kubectl apply -f nginx.yaml
  3. Verify that the NGINX pod is running: Expected output:

       kubectl get pods -l app=nginx
       NAME                     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 services

Make 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.