安装依赖工具并验证集群
本页面介绍了如何准备环境和集群,以便为 Google Cloud外部的 Kubernetes 工作负载安装集群内 Cloud Service Mesh。
安装所需的工具
您可以在 Cloud Shell 或运行 Linux 的本地机器上运行 asmcli。Cloud Shell 会预安装所有必需的工具。
如果您在本地运行 asmcli,请确保已安装以下工具:
- Google Cloud CLI
- 标准命令行工具:
awk、curl、grep、sed、tr gitkubectljq- (可选,以便测试连接)netcat (
nc)
配置 gcloud
即使您使用的是 Cloud Shell,仍请执行以下步骤。
使用 Google Cloud CLI 进行身份验证:
gcloud auth login --project PROJECT_ID更新组件:
gcloud components update
将当前上下文设置为用户集群:
根据特定于平台的说明,将 kubectl 上下文设置为指向Google Cloud 外部的集群。
下载 asmcli
本部分介绍如何下载 asmcli。
将用于安装 Cloud Service Mesh 1.27.1 的版本下载到当前工作目录:
curl https://storage.googleapis.com/csm-artifacts/asm/asmcli_1.27 > asmcli预期输出:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 167k 100 167k 0 0 701k 0 --:--:-- --:--:-- --:--:-- 701k让该脚本可执行:
chmod +x asmcli
授予集群管理员权限
确保您已将上下文设置为您的用户集群:
kubectl config use-context CONTEXT
向您的用户账号(您的 Google Cloud 电子邮件地址)授予集群管理员权限。您需要这些权限来创建 Cloud Service Mesh 所需的基于角色的访问控制 (RBAC) 规则:
kubectl create clusterrolebinding cluster-admin-binding \ --clusterrole=cluster-admin \ --user=USER_ACCOUNT
验证项目和集群
您可以运行 asmcli validate,确保项目和集群已按要求设置,以便安装 Cloud Service Mesh。使用此选项时,asmcli 不会对您的项目或集群进行任何更改,也不会安装 Cloud Service Mesh。
asmcli 会验证以下内容:
您的环境拥有所需的工具。
集群符合最低要求。
您对指定项目拥有所需权限。
项目已启用所有必需的 Google API。
默认情况下,asmcli 会下载并解压缩安装文件,并将 GitHub 中的 asm 配置软件包下载到临时目录中。在退出之前,asmcli 会输出一条消息,提供临时目录的名称。我们建议您使用 --output_dir DIR_PATH 选项指定下载目录。--output_dir 选项可方便您使用 istioctl 命令行工具。您可能需要 istioctl 来排查配置问题。此外,用于通过 asmcli 启用可选功能的配置文件包含在 asm/istio/options 目录中。
运行以下命令以验证配置并将安装文件和 asm 软件包下载到 OUTPUT_DIR 目录。
使用以下命令在以下平台上运行 asmcli validate:Google Distributed Cloud for VMware(纯软件)、Google Distributed Cloud for Bare Metal(纯软件)、GKE on AWS(已弃用)、GKE on Azure(已弃用)、Amazon EKS(已弃用)和 Microsoft AKS(已弃用)。
将当前上下文设置为用户集群:
kubectl config use-context CLUSTER_NAME运行以下命令以验证配置并将安装文件和
asm软件包下载到OUTPUT_DIR目录:./asmcli validate \ --kubeconfig KUBECONFIG_FILE \ --fleet_id FLEET_PROJECT_ID \ --output_dir DIR_PATH \ --platform multicloud--kubeconfig:kubeconfig的路径。您可以指定相对路径或完整路径。环境变量$PWD不适用于此处。--fleet_id:舰队宿主项目的项目 ID。asmcli validate检查集群是否已注册到指定的舰队。--output_dir添加此选项可指定asmcli在其中下载asm软件包并提取安装文件的目录,其中包含istioctl、示例和清单。否则,asmcli会将文件下载到tmp目录。您可以指定相对路径或完整路径。环境变量$PWD不适用于此处。--platform multicloud:指定平台是 Google Cloud以外的平台,例如本地平台或多云平台。
成功后,asmcli 输出以下内容:
asmcli: Setting up necessary files... asmcli: Using asm_kubeconfig as the kubeconfig... asmcli: Checking installation tool dependencies... asmcli: Fetching/writing GCP credentials to kubeconfig file... asmcli: Verifying connectivity (10s)... asmcli: kubeconfig set to asm_kubeconfig asmcli: using context gke_example-project-12345_us-central1_cluster-2 asmcli: Getting account information... asmcli: Downloading ASM.. asmcli: Downloading ASM kpt package... fetching package "/asm" from "https://github.com/GoogleCloudPlatform/anthos-service-mesh-packages" to "asm" asmcli: Checking required APIs... asmcli: Checking for project example-project-12345... asmcli: Reading labels for us-central1/cluster-2... asmcli: Checking for istio-system namespace... asmcli: Confirming node pool requirements for example-project-12345/us-central1/cluster-2... asmcli: Checking Istio installations... asmcli: [WARNING]: There is no way to validate that the meshconfig API has been initialized. asmcli: [WARNING]: This needs to happen once per GCP project. If the API has not been initialized asmcli: [WARNING]: for example-project-12345, please re-run this tool with the --enable_gcp_components asmcli: [WARNING]: flag. Otherwise, installation will succeed but Anthos Service Mesh asmcli: [WARNING]: will not function correctly. asmcli: Successfully validated all requirements to install ASM.
如果某一个测试未通过验证,asmcli 将输出错误消息。例如,如果您的项目未启用所有必需的 Google API,您会看到以下错误:
ERROR: One or more APIs are not enabled. Please enable them and retry, or run `asmcli` with the '--enable_gcp_apis' flag to allow `asmcli` to enable them on your behalf.
如果您收到错误消息,指出需要使用启用标志运行 asmcli,您可以采取以下措施:
在运行
asmcli来执行实际安装时,添加错误消息中的特定标志或添加--enable_all标志。如果您愿意,可以在运行
asmcli之前自行更新项目和集群,如自行设置项目和 GKE 集群所述。
请注意,asmcli validate 不允许任何启用标志,因为它仅验证项目和集群已准备好进行安装。
检查集群安装和升级要求
在升级之前,您应检查配置是否与新版本的 Cloud Service Mesh 兼容。
切换到您在
--output_dir中指定的目录。运行以下命令以检查 Kubernetes 集群是否满足安装和升级要求。请确保使用与新版本 Cloud Service Mesh 一起分发的
istioctl版本。istioctl experimental precheck