All Products
Search
Document Center

Alibaba Cloud Service Mesh:Preparations for Layer 7 routing

Last Updated:Mar 10, 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 workloads that the routing tutorials reference.

This topic covers two steps: confirm that your ASM instance, ACK cluster, and sidecar injection are ready, then deploy the sample services used in the routing tutorials.

Prerequisites

Before you begin, make sure that you have:

Deploy sample workloads

The Layer 7 routing tutorials use four sample services. Deploy only the services required for the tutorial you plan to follow.

ServicePurposeListens on
helloworldMulti-version service (v1, v2) for testing version-based routing and traffic splittingPort 5000
sleepClient pod with curl for sending test requests to other services in the meshPort 80
HTTPBinHTTP testing endpoint that echoes request details (headers, paths, methods) back to the callerPort 8000
NGINXStatic web server for testing basic routing rulesPort 8000

Connect kubectl to your ACK cluster using the kubeconfig file, then follow the sections below.

Deploy the helloworld service

helloworld runs two versions (v1 and v2) of the same application. This makes it suitable for testing version-based routing and traffic splitting.

  1. Save the following YAML as helloworld-application.yaml:

    Expand to view 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. Deploy the service:

    kubectl apply -f helloworld-application.yaml
  3. Verify the deployment: Expected output: A READY value of 2/2 confirms that both the application container and the sidecar proxy are running.

    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

sleep acts as a client pod. It stays idle and provides a curl environment for sending test requests to other services in the mesh.

  1. Save the following YAML as sleep-application.yaml:

    Expand to view 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. Deploy the service:

    kubectl apply -f sleep-application.yaml
  3. Verify the deployment: 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 echoes back request details -- headers, URI paths, and methods. Use it to verify that routing rules forward requests to the correct destination.

  1. Save the following YAML as httpbin-application.yaml:

    Expand to view 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. Deploy the service:

    kubectl apply -f httpbin-application.yaml
  3. Verify the deployment: 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 static content. Use it in tutorials that demonstrate basic URI path routing.

  1. Save the following YAML as nginx.yaml:

    Expand to view 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. Deploy the service:

    kubectl apply -f nginx.yaml
  3. Verify the deployment: Expected output:

    kubectl get pods -l app=nginx
    NAME                     READY   STATUS    RESTARTS   AGE
    nginx-xxxxxxxxx-xxxxx    2/2     Running   0          30s

Verify all deployments

After you deploy the required services, confirm that all pods are running with sidecar injection:

kubectl get pods

Every pod should show 2/2 in the READY column. This confirms that both the application container and the Istio sidecar proxy are injected and running.