在 Azure Kubernetes 服务 (AKS) 上与 Open Service Mesh 集成

Open Service Mesh (OSM) 加载项与 Azure 和某些开源项目提供的功能集成。

重要

Microsoft已宣布停用 AKS 的开放服务网格(OSM)加载项。 上游 OSM 项目也已由 Cloud Native Computing Foundation (CNCF) 停用。 识别任何现有的 OSM 配置,并将其迁移到等效的 Istio 配置。 有关迁移步骤,请参阅 将 Open Service Mesh(OSM)配置迁移到 Istio 的迁移指南

重要

AKS 支持策略未涵盖与开源项目的集成。

流入量

入口允许将网格外部的流量路由到网格内的服务。 借助 OSM,可以将大多数入口解决方案配置为使用网格,但 OSM 最适合以下解决方案之一:

将用于容器的 Azure 应用程序网关与用于 HTTP 入口的 OSM 加载项配合使用

创建命名空间并部署应用程序服务

  1. 安装 AGIC 入口控制器。

  2. 使用 kubectl create ns 命令为应用程序服务创建命名空间。

    kubectl create ns httpbin
    
  3. 使用 osm namespace add OSM CLI 命令将命名空间添加到网格。

    osm namespace add httpbin
    
  4. 使用 kubectl apply 命令将应用程序服务部署到命名空间。

    export RELEASE_BRANCH=release-v1.2
    kubectl apply -f https://raw.githubusercontent.com/openservicemesh/osm-docs/$RELEASE_BRANCH/manifests/samples/httpbin/httpbin.yaml -n httpbin
    
  5. 验证 Pod 是否已启动并运行,并使用 kubectl get pods 命令注入 envoy sidecar。

    kubectl get pods -n httpbin
    

    输出应类似于以下示例输出:

    NAME                      READY   STATUS    RESTARTS   AGE
    httpbin-7c6464475-9wrr8   2/2     Running   0          6d20h
    
  6. 使用 kubectl get svc 命令列出服务的详细信息。

    kubectl get svc -n httpbin
    

    输出应类似于以下示例输出:

    NAME      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)     AGE
    httpbin   ClusterIP   10.0.92.135   <none>        14001/TCP   6d20h
    

部署入口配置并验证对应用程序服务的访问权限

  1. 部署下面的 GatewayHTTPRouteIngressBackend 配置,以允许外部客户端使用 httpbin 命令在端口 14001 上访问 kubectl apply 服务。

    kubectl apply -f <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: gateway-01
      namespace: httpbin
      annotations:
        alb.networking.azure.io/alb-namespace: <alb-namespace>
        alb.networking.azure.io/alb-name: <alb-name>
    spec:
      gatewayClassName: azure-alb-external
      listeners:
      - name: httpbin-listener
        port: 80
        protocol: HTTP
        allowedRoutes:
          namespaces:
            from: Same
    ---
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: httpbin-route
      namespace: httpbin
    spec:
      parentRefs:
      - name: gateway-01
      rules:
      - backendRefs:
        - name: httpbin
          port: 14001
    ---
    kind: IngressBackend
    apiVersion: policy.openservicemesh.io/v1alpha1
    metadata:
      name: httpbin
      namespace: httpbin
    spec:
      backends:
     - name: httpbin
        port:
          number: 14001 # targetPort of httpbin service
          protocol: http
      sources:
     - kind: IPRange
        name: 10.0.0.0/8
    EOF
    
  2. 使用GatewayHTTPRoute命令验证kubectl get gatewaykubectl get httproute资源是否已成功部署。 记下网关资源上的外部完全合格域名。

    # Gateway resource
    kubectl get gateway gateway-01 -n test-infra -o yaml
    # HTTPRotue resource
    kubectl get httproute contoso-route -n test-infra -o yaml
    

    输出 Gateway 应类似于以下示例输出:

    status:
      addresses:
      - type: Hostname
        value: xxxx.yyyy.alb.azure.com
      conditions:
      - lastTransitionTime: "2023-06-19T21:04:55Z"
        message: Valid Gateway
        observedGeneration: 1
        reason: Accepted
        status: "True"
        type: Accepted
      - lastTransitionTime: "2023-06-19T21:04:55Z"
        message: Application Gateway For Containers resource has been successfully updated.
        observedGeneration: 1
        reason: Programmed
        status: "True"
        type: Programmed
      listeners:
      - attachedRoutes: 0
        conditions:
        - lastTransitionTime: "2023-06-19T21:04:55Z"
          message: ""
          observedGeneration: 1
          reason: ResolvedRefs
          status: "True"
          type: ResolvedRefs
        - lastTransitionTime: "2023-06-19T21:04:55Z"
          message: Listener is accepted
          observedGeneration: 1
          reason: Accepted
          status: "True"
          type: Accepted
        - lastTransitionTime: "2023-06-19T21:04:55Z"
          message: Application Gateway For Containers resource has been successfully updated.
          observedGeneration: 1
          reason: Programmed
          status: "True"
          type: Programmed
        name: https-listener
        supportedKinds:
        - group: gateway.networking.k8s.io
          kind: HTTPRoute
    
  3. 使用IngressBackend命令验证kubectl get ingressbackend对象是否已成功部署。

    kubectl get ingressbackend -n httpbin
    

    输出应类似于以下示例输出:

    NAME      STATUS
    httpbin   committed
    
  4. 验证您是否可以使用入口服务的外部 IP 地址和以下命令httpbin来访问curl服务。

    fqdn=$(kubectl get gateway gateway-01 -n httpbin -o jsonpath='{.status.addresses[0].value}')
    curl -sI http://$fqdn/get
    
  5. 确认收到响应 status 200

指标可观测性

指标可观测性使您可以查看和分析网格的指标以及网格中部署的情况。 借助 OSM,可以使用 Prometheus 和 Grafana 实现指标可观测性,但 AKS 支持策略未涵盖这些集成。

还可以将 OSM 与 Azure Monitor 集成。

在网格上启用指标以与 Azure Monitor 集成之前,请确保满足以下先决条件:

  • 在群集上启用 Azure Monitor。
  • 为 AKS 群集启用 OSM 加载项。
  • 将应用程序命名空间加入网格。
  1. 使用 osm metrics enable 命令为网格中的命名空间启用指标。

    osm metrics enable --namespace myappnamespace
    
  2. 在命名空间中创建 kube-system ConfigMap,使 Azure Monitor 能够监视命名空间。 例如,创建一个包含以下内容的 monitor-configmap.yaml 以监控 myappnamespace:

    kind: ConfigMap
    apiVersion: v1
    data:
      schema-version: v1
      config-version: ver1
      osm-metric-collection-configuration: |-
        # OSM metric collection settings
        [osm_metric_collection_configuration]
          [osm_metric_collection_configuration.settings]
              # Namespaces to monitor
              monitor_namespaces = ["myappnamespace"]
    metadata:
      name: container-azm-ms-osmconfig
      namespace: kube-system
    
  3. 使用“kubectl apply”命令来应用 ConfigMap。

    kubectl apply -f monitor-configmap.yaml
    
  4. 导航到 Azure 门户并选择 AKS 群集。

  5. 在“监控”下选择“日志”。

  6. “监视 ”部分中,查询 InsightsMetrics 表以查看已启用命名空间中的指标。 例如,以下查询显示默认命名空间的 envoy 指标:

    InsightsMetrics
    |     where Name contains "envoy"
    |     extend t=parse_json(Tags)
    |     where t.namespace == "default"
    

自动化和开发人员工具

OSM 可以与某些自动化项目和开发人员工具集成,以帮助作员和开发人员生成和发布应用程序。 例如,OSM 与 Flagger 集成,用于渐进式交付, Dapr 用于生成应用程序。 AKS 支持策略未涵盖 OSM 与 Flagger 和 Dapr 的集成。

外部授权

外部授权允许将 HTTP 请求的授权卸载到外部服务。 OSM 可以通过与 开放策略代理(OPA)集成来使用外部授权,但 AKS 支持策略未涵盖该集成。

证书管理

OSM 具有几种用于在 AKS 群集上运行的证书类型。 OSM 包括自己的名为 Tresor 的证书管理器,默认情况下使用。 或者,OSM 允许与 Hashicorp Vault证书管理器集成,但 AKS 支持策略未涵盖这些集成。

后续步骤

本文介绍了开放服务网格(OSM)加载项与 Azure 和某些开源项目提供的功能集成。 若要了解有关 OSM 的详细信息,请参阅 AKS 中的关于 OSM