安裝依附工具並驗證叢集
本頁面說明如何準備環境和叢集,以便在 GKE 上安裝叢集內的 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設為指向叢集。gcloud container clusters get-credentials CLUSTER_NAME \ --location CLUSTER_LOCATION \ --project PROJECT_ID
下載 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 來排解設定問題,或在私人 GKE 叢集中設定多叢集網格。此外,使用 asmcli 啟用選用功能的設定檔也包含在 asm/istio/options 目錄中。
執行下列指令,驗證設定,並將安裝檔案和 asm 套件下載至 OUTPUT_DIR 目錄。
./asmcli validate \
--project_id PROJECT_ID \
--cluster_name CLUSTER_NAME \
--cluster_location CLUSTER_LOCATION \
--fleet_id FLEET_PROJECT_ID \
--output_dir DIR_PATH
--project_id、--cluster_name和--cluster_location:指定叢集所在的專案 ID、叢集名稱,以及叢集區或區域。--fleet_id機群主機專案的專案 ID。asmcli validate會檢查叢集是否已註冊至指定的機群。--output_dir加入這個選項,即可指定asmcli下載asm套件並擷取安裝檔案的目錄,其中包含istioctl、範例和資訊清單。否則,asmcli會將檔案下載至tmp目錄。您可以指定相對路徑或完整路徑。環境變數$PWD在這裡無效。
成功後,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