文档

准备工作

更新时间:

L7路由支持多种能力,例如URI路径匹配、请求头匹配等。本文介绍实现L7路由相关能力的准备工作。

前提条件

步骤一:将数据面模式设置为Ambient

将全局命名空间default的数据面模式设置为Ambient。

  1. 登录ASM控制台,在左侧导航栏,选择服务网格 > 网格管理

  2. 网格管理页面,单击目标实例名称,然后在左侧导航栏,选择网格实例 > 全局命名空间

  3. 全局命名空间页面的数据面模式列,单击default命名空间对应的切换为Ambient Mesh模式,在确认对话框,单击确定

步骤二:在数据面集群中部署服务

请结合实际场景,按需部署helloworld、sleep、httpbin、nginx或mocka服务。

部署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
      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
      name: nginx
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          serviceAccountName: nginx
          containers:
            - image: 'nginx:1.7.9'
              imagePullPolicy: IfNotPresent
              name: nginx
              ports:
                - containerPort: 80
                  protocol: TCP
              resources:
                limits:
                  cpu: 500m
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
  2. 在ACK集群对应的KubeConfig环境下,执行以下命令,部署nginx应用。

    kubectl apply -f nginx.yaml

部署mocka服务

  1. 使用以下内容,创建mocka-application.yaml。

    展开查看mocka-application.yaml

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: mocka
      namespace: default
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: mocka
      labels:
        app: mocka
        service: mocka
    spec:
      ports:
      - port: 8000
        name: http
      selector:
        app: mocka
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mocka-v1
      labels:
        app: mocka
        version: v1
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: mocka
          version: v1
          ASM_TRAFFIC_TAG: v1
      template:
        metadata:
          labels:
            app: mocka
            version: v1
            ASM_TRAFFIC_TAG: v1
        spec:
          serviceAccountName: mocka
          containers:
          - name: default
            image: docker.io/vifoggy/gobin:1.0.0
            imagePullPolicy: IfNotPresent
            env:
            - name: version
              value: v1
            - name: app
              value: mocka
            ports:
            - containerPort: 8000
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: mocka-v2
      labels:
        app: mocka
        version: v2
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: mocka
          version: v2
          ASM_TRAFFIC_TAG: v2
      template:
        metadata:
          labels:
            app: mocka
            version: v2
            ASM_TRAFFIC_TAG: v2
        spec:
          serviceAccountName: mocka
          containers:
          - name: default
            image: docker.io/vifoggy/gobin:1.0.0
            imagePullPolicy: IfNotPresent
            env:
            - name: version
              value: v2
            - name: app
              value: mocka
            ports:
            - containerPort: 8000
  2. 在ACK集群对应的KubeConfig环境下,执行以下命令,部署mocka应用。

    kubectl apply -f mocka-application.yaml
  • 本页导读 (1)