全部產品
Search
文件中心

Alibaba Cloud Service Mesh:準備工作

更新時間:Jun 30, 2024

L7路由支援多種能力,例如URI路徑匹配、要求標頭匹配等。本文介紹實現L7路由相關能力的準備工作。

前提條件

操作步驟

請結合實際情境,按需在資料面叢集中部署helloworld、sleep、httpbin或nginx服務。

部署helloworld服務

  1. 使用以下內容,建立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. 在ACK叢集對應的KubeConfig環境下,執行以下命令,部署helloworld應用。

    kubectl apply -f helloworld-application.yaml

部署sleep服務

  1. 使用以下內容,建立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. 在ACK叢集對應的KubeConfig環境下,執行以下命令,部署sleep應用。

    kubectl apply -f sleep-application.yaml

部署httpbin服務

  1. 使用以下內容,建立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. 在ACK叢集對應的KubeConfig環境下,執行以下命令,部署httpbin應用。

    kubectl apply -f httpbin-application.yaml

部署nginx服務

  1. 使用以下內容,建立nginx應用。

    展開查看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. 在ACK叢集對應的KubeConfig環境下,執行以下命令,部署nginx應用。

    kubectl apply -f nginx.yaml