All Products
Search
Document Center

Alibaba Cloud Service Mesh:Preparations

Last Updated:Nov 04, 2024

Service Mesh (ASM) supports two sidecarless modes: Ambient Mesh mode and Alibaba Centralized Mesh Gateway (ACMG) mode. This topic describes how to deploy sample applications in these two modes. This helps you prepare the environment in advance so that you can experience the features of the sidecarless modes as soon as possible.

Prerequisites

  • A Container Service for Kubernetes (ACK) cluster that meets the specified conditions is created. For more information, see the "Supported Kubernetes clusters and configurations" section in Limits.

  • An ASM instance is created and enabled with the Ambient Mesh mode or ACMG mode.

    In the Dataplane Mode section of the Create Service Mesh page, select Enable Ambient Mesh mode or Enable ACMG Mode. Configure other settings based on your business requirements. For more information, see Create an ASM instance.

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

  • An ingress gateway is created. For more information, see Create an ingress gateway.

Deploy sample applications

In this example, the Bookinfo application is deployed. For more information, see Deploy an application in an ACK cluster that is added to an ASM instance.

Deploy sample applications in the ACK cluster

  1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose ASM Instance > Global Namespace.

  3. Enable the Ambient Mesh mode or ACMG mode.

    1. Ambient Mesh mode

      1. On the Global Namespace page, find the default namespace and click Switch to Ambient Mesh Mode in the Dataplane Mode column. In the Submit message, click OK.

    2. ACMG mode

      1. Use kubectl to connect to the ASM instance based on the information in the kubeconfig file and enable the ACMG mode.

        kubectl label namespace default istio.io/dataplane-mode=acmg
  4. Download the YAML file of the Bookinfo application from the Istio repository on GitHub. Then, run the following command to deploy the Bookinfo application in the default namespace:

    kubectl apply -f  bookinfo.yaml
  5. Deploy a sleep application.

    1. Create a sleep.yaml file that contains the following content:

      Expand to view the 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", "infinity"]
              imagePullPolicy: IfNotPresent
              volumeMounts:
              - mountPath: /etc/sleep/tls
                name: secret-volume
            volumes:
            - name: secret-volume
              secret:
                secretName: sleep-secret
                optional: true
      ---
    2. Run the following command to deploy the sleep application in the default namespace:

      kubectl apply -f  sleep.yaml
  6. Deploy a notsleep application.

    1. Create a notsleep.yaml file that contains the following content:

      Expand to view the YAML file

      apiVersion: v1
      kind: ServiceAccount
      metadata:
        name: notsleep
      ---
      apiVersion: v1
      kind: Service
      metadata:
        name: notsleep
        labels:
          app: notsleep
          service: notsleep
      spec:
        ports:
        - port: 80
          name: http
        selector:
          app: notsleep
      ---
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: notsleep
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: notsleep
        template:
          metadata:
            labels:
              app: notsleep
          spec:
            affinity:
              podAntiAffinity:
                preferredDuringSchedulingIgnoredDuringExecution:
                - weight: 100
                  podAffinityTerm:
                    labelSelector:
                      matchExpressions:
                      - key: app
                        operator: In
                        values:
                        - productpage
                    topologyKey: kubernetes.io/hostname 
            terminationGracePeriodSeconds: 0
            serviceAccountName: notsleep
            containers:
            - name: notsleep
              image: curlimages/curl
              command: ["/bin/sleep", "3650d"]
              imagePullPolicy: IfNotPresent
              volumeMounts:
              - mountPath: /etc/sleep/tls
                name: secret-volume
            volumes:
            - name: secret-volume
              secret:
                secretName: notsleep-secret
                optional: true
      ---
    2. Run the following command to deploy the notsleep application in the default namespace:

      kubectl apply -f  notsleep.yaml

Deploy mesh resources in the ASM instance

  1. Create a bookinfo-gateway.yaml file that contains the following content.

    The YAML file is used to create an Istio gateway and a virtual service.

    Expand to view the bookinfo-gateway.yaml file

    apiVersion: networking.istio.io/v1alpha3
    kind: Gateway
    metadata:
      name: bookinfo-gateway
    spec:
      selector:
        istio: ingressgateway # use istio default controller
      servers:
      - port:
          number: 80
          name: http
          protocol: HTTP
        hosts:
        - "*"
    ---
    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: bookinfo
    spec:
      hosts:
      - "*"
      gateways:
      - bookinfo-gateway
      http:
      - match:
        - uri:
            exact: /productpage
        - uri:
            prefix: /static
        - uri:
            exact: /login
        - uri:
            exact: /logout
        - uri:
            prefix: /api/v1/products
        route:
        - destination:
            host: productpage
            port:
              number: 9080
    
  2. Use kubectl to connect to the ASM instance based on the information in the kubeconfig file, and then run the following command to deploy mesh resources:

    kubectl apply -f bookinfo-gateway.yaml

Verify basic features

  1. Run the following commands to configure environment variables for the ingress gateway:

    export GATEWAY_HOST=istio-ingressgateway.istio-system
    export GATEWAY_SERVICE_ACCOUNT=ns/istio-system/sa/istio-ingressgateway
  2. Run the following commands to test whether the Bookinfo application works properly with or without an ingress gateway.

    1. Run the following command:

      kubectl exec deploy/sleep -- curl -s "http://$GATEWAY_HOST/productpage" | grep -o "<title>.*</title>"

      Expected output:

      <title>Simple Bookstore App</title>
    2. Run the following command:

      kubectl exec deploy/sleep -- curl -s http://productpage:9080/ | grep -o "<title>.*</title>"

      Expected output:

      <title>Simple Bookstore App</title>
    3. Run the following command:

      kubectl exec deploy/notsleep -- curl -s http://productpage:9080/ | grep -o "<title>.*</title>"

      Expected output:

      <title>Simple Bookstore App</title>

      The preceding output indicates that the Bookinfo application can work properly with or without an ingress gateway.