在本地安装 Anthos Service Mesh

Anthos Service Mesh 是一种与 Istio 兼容的框架,用于连接、监控和保护在 Google Kubernetes Engine (GKE) 和 GKE on VMware 上运行的服务。它可让您创建部署服务的网络并进行负载均衡、服务到服务身份验证、监控等,无需对服务代码进行任何更改。Anthos Service Mesh 会自动为每个应用的 Pod 注入边车代理。边车代理会拦截进出 pod 的所有网络流量。Anthos Service Mesh 还配置了一个入站流量网关来管理该网格的入站流量。您可以使用开源 Istio API 来配置在辅助信息文件和网关上强制执行的政策。

本指南介绍如何在 GKE on VMware 上进行 Anthos Service Mesh 版本 1.4.10-asm.18 的全新安装。如果您安装了先前版本的 Anthos Service Mesh,请参阅在 GKE on VMware 上升级 Anthos Service Mesh

此安装操作会在 GKE on VMware 上启用支持的核心 Istio 功能。请注意,在 GKE on VMware 上目前不支持 Anthos Service Mesh 代管式组件

关于控制层面组件

GKE on VMware 预安装有以下 Istio 组件:

  • Citadel 安装在 kube-system 命名空间中。
  • Pilot 和 Istio 入站流量网关安装在 gke-system 命名空间中。

GKE on VMware 使用这些组件来启用入站流量,以及保护由 Google 控制的组件之间的通信。如果您只需要入站流量功能,则无需安装 OSS Istio 或 Anthos Service Mesh。如需详细了解如何配置入站流量,请参阅启用入站流量

安装 Anthos Service Mesh 时,其组件会安装在 istio-system 命名空间中。由于 Anthos Service Mesh 组件位于不同的命名空间中,因此不会与 GKE on VMware 预安装的 Istio 组件发生冲突。

准备工作

在开始设置前,请查看以下要求和限制。

使用要求

  • 您必须拥有 GKE Enterprise 试用许可或订阅。如需了解详情,请参阅 GKE Enterprise 价格指南

  • 确保安装 Anthos Service Mesh 的用户集群至少具有 4 个 vCPU、15 GB 内存和 4 个副本。

  • 在部署工作负载之前,请查看 Pod 和服务要求

  • 确保您的集群版本列在受支持的环境中。如需检查集群版本:

    gkectl version
    

    系统会显示如下所示的输出:

    1.2.0-gke.6 (git-0912663b0)
    

限制

仅支持每个 Google Cloud 项目安装一次 Anthos Service Mesh。不支持在单个项目中进行多次网格部署

设置环境

在本地机器上,安装并初始化 Google Cloud CLI

如果您已安装 gcloud CLI,请执行以下操作:

  1. 使用 gcloud CLI 进行身份验证:

    gcloud auth login
    
  2. 更新组件:

    gcloud components update
    
  3. 安装 kubectl

    gcloud components install kubectl
    
  4. 获取在其中创建集群的项目的项目 ID:

    gcloud

    gcloud projects list

    控制台

    1. 在 Google Cloud 控制台中,前往信息中心页面

      前往“信息中心”页面

    2. 点击页面顶部的从以下列表中选择:下拉列表。在随即显示的从以下列表中选择:窗口中,选择您的项目。项目 ID 会显示在项目信息中心的项目信息卡片上。

  5. 设置 Google Cloud CLI 的默认项目 ID:

    gcloud config set project PROJECT_ID

设置凭据和权限

在继续操作之前,确保您已启用所有必需 API。如果您有任何疑问,不妨再次运行 gcloud services enable 命令。

  1. 确保您对要安装 Anthos Service Mesh 的用户集群拥有 kubectl。请注意,您只能在用户集群上安装 Anthos Service Mesh,不能在管理员集群上安装。
  2. 向当前用户授予集群管理员权限。您需要这些权限,以便为 Anthos Service Mesh 创建必要的基于角色的访问权限控制 (RBAC) 规则:
    kubectl create clusterrolebinding cluster-admin-binding \
      --clusterrole=cluster-admin \
      --user="$(gcloud config get-value core/account)"

    如果您看到 "cluster-admin-binding" already exists 错误,可以放心地忽略该错误并继续使用现有的集群管理员绑定。

准备安装 Anthos Service Mesh

    Linux

  1. 将 Anthos Service Mesh 安装文件下载到当前工作目录中:
    curl -LO https://storage.googleapis.com/gke-release/asm/istio-1.4.10-asm.18-linux.tar.gz
  2. 下载签名文件并使用 openssl 验证签名:
    curl -LO https://storage.googleapis.com/gke-release/asm/istio-1.4.10-asm.18-linux.tar.gz.1.sig
    openssl dgst -verify - -signature istio-1.4.10-asm.18-linux.tar.gz.1.sig istio-1.4.10-asm.18-linux.tar.gz <<'EOF'
    -----BEGIN PUBLIC KEY-----
    MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEWZrGCUaJJr1H8a36sG4UUoXvlXvZ
    wQfk16sxprI2gOJ2vFFggdq3ixF2h4qNBt0kI7ciDhgpwS8t+/960IsIgw==
    -----END PUBLIC KEY-----
    EOF

    预期输出为 Verified OK

  3. Mac OS

  4. 将 Anthos Service Mesh 安装文件下载到当前工作目录中:
    curl -LO https://storage.googleapis.com/gke-release/asm/istio-1.4.10-asm.18-osx.tar.gz
  5. 下载签名文件并使用 openssl 验证签名:
    curl -LO https://storage.googleapis.com/gke-release/asm/istio-1.4.10-asm.18-osx.tar.gz.1.sig
    openssl dgst -sha256 -verify /dev/stdin -signature istio-1.4.10-asm.18-osx.tar.gz.1.sig istio-1.4.10-asm.18-osx.tar.gz <<'EOF'
    -----BEGIN PUBLIC KEY-----
    MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEWZrGCUaJJr1H8a36sG4UUoXvlXvZ
    wQfk16sxprI2gOJ2vFFggdq3ixF2h4qNBt0kI7ciDhgpwS8t+/960IsIgw==
    -----END PUBLIC KEY-----
    EOF

    预期输出为 Verified OK

  6. Windows

  7. 将 Anthos Service Mesh 安装文件下载到当前工作目录中:
    curl -LO https://storage.googleapis.com/gke-release/asm/istio-1.4.10-asm.18-win.zip
  8. 下载签名文件并使用 openssl 验证签名:
    curl -LO https://storage.googleapis.com/gke-release/asm/istio-1.4.10-asm.18-win.zip.1.sig
    openssl dgst -verify - -signature istio-1.4.10-asm.18-win.zip.1.sig istio-1.4.10-asm.18-win.zip <<'EOF'
    -----BEGIN PUBLIC KEY-----
    MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEWZrGCUaJJr1H8a36sG4UUoXvlXvZ
    wQfk16sxprI2gOJ2vFFggdq3ixF2h4qNBt0kI7ciDhgpwS8t+/960IsIgw==
    -----END PUBLIC KEY-----
    EOF

    预期输出为 Verified OK

  9. 将文件内容提取到文件系统上的任意位置。例如,如需将内容提取到当前工作目录,请运行以下命令:
    tar xzf istio-1.4.10-asm.18-linux.tar.gz

    该命令会在当前工作目录中创建一个名为 istio-1.4.10-asm.18 的安装目录,其中包含:

    • samples 中的示例应用
    • bin 目录中的以下工具:
      • istioctl:您使用 istioctl 来安装 Anthos Service Mesh。
      • asmctl:安装 Anthos Service Mesh 后,您可以使用 asmctl 来帮助验证安全配置。(目前,GKE on VMware 不支持 asmctl。)

  10. 确保您位于 Anthos Service Mesh 安装的根目录。
    cd istio-1.4.10-asm.18
  11. 为方便起见,请将 /bin 目录中的工具添加到 PATH:
    export PATH=$PWD/bin:$PATH

创建 istio-system 命名空间

为控制层面组件创建一个名为 istio-system 的命名空间:

kubectl create namespace istio-system

安装 Anthos Service Mesh

本部分介绍如何安装 Anthos Service Mesh 以及如何启用在支持的功能页面中列出的支持的默认功能。如需了解如何启用支持的可选功能,请参阅启用可选功能

如需安装 Anthos Service Mesh,请运行以下命令:

选择以下任一命令,以在 PERMISSIVE 双向 TLS (mTLS) 身份验证模式或 STRICT mTLS 模式下配置 Anthos Service Mesh。

PERMISSIVE mTLS

istioctl manifest apply --set profile=asm-onprem

STRICT mTLS

istioctl manifest apply --set profile=asm-onprem \
  --set values.global.mtls.enabled=true

检查控制层面组件

检查 istio-system 中的控制层面 Pod 是否已启动:

kubectl get pod -n istio-system

预期会看到类似如下所示的输出:

NAME                                      READY   STATUS      RESTARTS   AGE
istio-citadel-85f4d775cd-dmpj2            1/1     Running     0          18m
istio-galley-5c65896ff7-m2pls             2/2     Running     0          18m
istio-ingressgateway-587cd459f-q6hqt      2/2     Running     0          18m
istio-pilot-9db77b99f-7wfb6               2/2     Running     0          18m
istio-sidecar-injector-69c4d9f875-dt8rn   1/1     Running     0          18m
promsd-55f464d964-lqs7w                   2/2     Running     0          18m

注入 Sidecar 代理

Anthos Service Mesh 使用边车代理来增强网络安全性、可靠性和可观测性。借助 Anthos Service Mesh,这些功能可以从应用的主容器中抽象出来,并在作为同一 Pod 中单独的容器提供的常见进程外代理中实现。

在安装 Anthos Service Mesh 之前在集群上运行的任何工作负载都需要注入或更新边车代理,以使其具有当前的 Anthos Service Mesh 版本。在部署新工作负载之前,确保配置边车代理注入,以便 Anthos Service Mesh 可以监控并保护流量。

您可以使用一个命令启用自动 Sidecar 注入,例如:

kubectl label namespace NAMESPACE istio-injection=enabled --overwrite

其中,NAMESPACE 是应用服务的命名空间的名称;如果未显式创建命名空间,则为 default

如需了解详情,请参阅注入 Sidecar 代理

配置外部 IP 地址

默认的 Anthos Service Mesh 安装假定为 LoadBalancer 服务自动分配外部 IP 地址。在 GKE on VMware 上并非如此。因此,您需要为 Anthos Service Mesh 入站流量网关资源手动分配 IP 地址。

如需配置外部 IP 地址,请根据集群的负载均衡模式,按照以下某一部分的说明执行操作:

集成负载均衡模式

  1. 打开 istio-ingressgateway Service 的配置:

    kubectl edit svc -n istio-system istio-ingressgateway
    

    istio-ingressgateway Service 的配置会在 shell 的默认文本编辑器中打开。

  2. 在文件中的规范 (spec) 块下添加以下行:

    loadBalancerIP: <your static external IP address>
    

    例如:

    spec:
     loadBalancerIP: 203.0.113.1
    
  3. 保存文件。

手动负载均衡模式

要在所选的负载均衡器上使用 VIP 地址公开 NodePort 类型的服务,您需要先找出 nodePort 值:

  1. 在 shell 中查看 istio-ingressgateway Service 的配置:

    kubectl get svc -n istio-system istio-ingressgateway -o yaml
    

    系统会显示 Anthos Service Mesh 网关的每个端口。命令输出如下所示:

     ...
     ports:
     - name: status-port
       nodePort: 30391
       port: 15020
       protocol: TCP
       targetPort: 15020
     - name: http2
       nodePort: 31380
       port: 80
       protocol: TCP
       targetPort: 80
     - name: https
       nodePort: 31390
       port: 443
       protocol: TCP
       targetPort: 443
     - name: tcp
       nodePort: 31400
       port: 31400
       protocol: TCP
       targetPort: 31400
     - name: https-kiali
       nodePort: 31073
       port: 15029
       protocol: TCP
       targetPort: 15029
     - name: https-prometheus
       nodePort: 30253
       port: 15030
       protocol: TCP
       targetPort: 15030
     - name: https-grafana
       nodePort: 30050
       port: 15031
       protocol: TCP
       targetPort: 15031
     - name: https-tracing
       nodePort: 31204
       port: 15032
       protocol: TCP
       targetPort: 15032
     - name: tls
       nodePort: 30158
       port: 15443
       protocol: TCP
       targetPort: 15443
     ...
    
  2. 通过负载均衡器公开这些端口。

    例如,名为 http2 的服务端口具有 port 80 和 nodePort 31380。假设您的用户集群的节点地址是 192.168.0.10192.168.0.11192.168.0.12,并且负载均衡器的 VIP 地址是 203.0.113.1

    配置负载均衡器以将发送到 203.0.113.1:80 的流量转发到 192.168.0.10:31380192.168.0.11:31380192.168.0.12:31380。您可以选择要在此给定 VIP 地址上公开的服务端口。

后续步骤