All Products
Search
Document Center

Alibaba Cloud Service Mesh:Preparations

Last Updated:Oct 11, 2023

Layer 7 routing supports multiple capabilities, such as URI path matching and request header matching. This topic describes the preparations for implementing capabilities related to Layer 7 routing.

Prerequisites

  • A Service Mesh (ASM) instance of Enterprise Edition is created. For more information, see Create an ASM instance.

    In the Dataplane Mode section of the Create Service Mesh page, do not select Enable Ambient Mesh mode.

  • A Container Service for Kubernetes (ACK) cluster is created. For more information about how to create a cluster, see Create an ACK dedicated cluster or Create an ACK managed cluster.

  • The cluster is added to the ASM instance. For more information, see Add a cluster to an ASM instance.

  • Automatic sidecar proxy injection is enabled for the default namespace. For more information, see the "Enable automatic sidecar proxy injection" section of the Manage global namespaces topic.

Procedure

Deploy the helloworld, sleep, HTTPBin, or NGINX services in the ACK cluster based on your business requirements.

Deploy the helloworld service

  1. Use the following content to create a helloworld-application.yaml file.

    Expand to view the helloworld-application.yaml file

    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. Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and then run the following command to deploy the helloworld service:

    kubectl apply -f helloworld-application.yaml

Deploy the sleep service

  1. Use the following content to create a sleep-application.yaml file.

    Expand to view the sleep-application.yaml file

    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. Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and then run the following command to deploy the sleep service:

    kubectl apply -f sleep-application.yaml

Deploy the HTTPBin service

  1. Use the following content to create an httpbin-application.yaml file.

    Expand to view the httpbin-application.yaml file

    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. Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and then run the following command to deploy the HTTPBin service:

    kubectl apply -f httpbin-application.yaml

Deploy the NGINX service

  1. Use the following content to create an nginx.yaml file.

    Expand to view the nginx.yaml file

    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. Use kubectl to connect to the ACK cluster based on the information in the kubeconfig file, and then run the following command to deploy the NGINX service:

    kubectl apply -f nginx.yaml