準備為 Cloud Service Mesh 設定 Gateway API
本頁說明如何在叢集中安裝閘道所需的自訂資源定義。
限制
- 不支援在同一機群中混用
gatewayconfig-api 和istioconfig-api 叢集。請確認機群中所有叢集的 config-api 都設為gateway。使用gcloud container fleet mesh describe --project FLEET_PROJECT_ID指令查看您為機群設定的內容。 gatewayconfig-api 叢集不支援多叢集服務探索和負載平衡。- 如果叢集是使用現有的
--management automatic旗標上線,叢集就會開始使用istio設定 API,且無法變更為gatewayAPI。 - 系統僅支援 FQDN。系統不支援簡稱。
資料層管理注意事項
如果是新 Pod,Google 會管理要注入的 Proxy 版本。請注意,受管理資料層會依據 Google Kubernetes Engine (GKE) 發布管道,判斷 Proxy 版本。
如果是現有 Pod,系統會被動管理 Proxy,由叢集中 Pod 的自然生命週期驅動。如要觸發更新並重新注入新版 Proxy,請重新啟動工作負載。
必要條件
本指南假設您已建立 Google Cloud 專案並安裝 kubectl。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Kubernetes Engine, GKE Hub, and Cloud Service Mesh APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Kubernetes Engine, GKE Hub, and Cloud Service Mesh APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. - CLUSTER_NAME 是叢集名稱
- LOCATION 是叢集的位置
- PROJECT_ID 是叢集的專案 ID
前往 Google Cloud 控制台的「Google Kubernetes Engine」頁面。
點選 add_box「建立」。
在「標準」部分,按一下「設定」。
在「叢集基本資訊」部分,完成下列操作:
- 輸入叢集的「名稱」。
- 在「位置類型」部分,為叢集選取 Compute Engine 區域。
在導覽窗格的「Node Pools」(節點集區) 區段下方,按一下「default-pool」,然後選取「Security」(安全性)。
在「Access scopes」(存取權範圍) 清單中,選取「Set access for each API」(針對各個 API 設定存取權),並將「Cloud Platform」(Cloud Platform) 設為「Enabled」(已啟用)。
在導覽窗格中,按一下「叢集」區段下方的「網路」。
在「叢集網路」清單中,選取「啟用 Gateway API」。
在導覽窗格中,按一下「叢集」部分下方的「安全性」。
在「安全性」清單中,選取「啟用 Workload Identity」。
點選「建立」。
將叢集註冊至機群:
gcloud container fleet memberships register CLUSTER_NAME \ --gke-cluster LOCATION/CLUSTER_NAME \ --project=PROJECT_ID確認叢集已向機群註冊:
gcloud container fleet memberships list --project=PROJECT_ID輸出內容類似如下:
NAME EXTERNAL_ID LOCATION my-cluster 91980bb9-593c-4b36-9170-96445c9edd39 us-west1啟用網狀功能:
gcloud container fleet mesh enable --project PROJECT_ID更新網格以使用 Gateway API:
gcloud alpha container fleet mesh update \ --config-api gateway \ --memberships CLUSTER_NAME \ --project PROJECT_ID說明 Cloud Service Mesh 資源的狀態,以驗證更新:
gcloud alpha container fleet mesh describe \ --project PROJECT_ID建立 YAML 檔案,指定使用 Gateway API:
echo "configapi: gateway" > mesh.yaml更新網格:
gcloud alpha container fleet mesh update --project FLEET_PROJECT_ID \ --fleet-default-member-config mesh.yaml建立叢集並向機群註冊,即可使用預設設定:
gcloud container clusters create CLUSTER_NAME \ --project PROJECT_ID \ --fleet-project FLEET_PROJECT_ID \ --location=LOCATION \啟用 Workload Identity Federation for GKE,並在節點上執行 GKE 中繼資料伺服器。
- CLUSTER_NAME 是叢集名稱
- LOCATION 是叢集的位置
- PROJECT_ID 是叢集的專案 ID
建立及註冊 GKE 叢集
gcloud
建立 GKE 叢集:
gcloud container clusters create CLUSTER_NAME \
--location=LOCATION \
--enable-ip-alias \
--scopes=https://www.googleapis.com/auth/cloud-platform \
--release-channel=regular \
--project=PROJECT_ID \
--gateway-api=standard \
--workload-pool=PROJECT_ID.svc.id.goog \
--workload-metadata=GKE_METADATA
其中:
控制台
叢集建立完成後,
設定權限
請注意,下列指令會將權限授予所有已通過驗證的使用者,但您可以使用 GKE 適用的工作負載身分聯盟,只將權限授予特定帳戶。如要瞭解 Workload Identity Federation for GKE 的運作方式,請參閱「關於 Workload Identity Federation for GKE」。如要設定 GKE 適用的工作負載身分聯盟,請參閱「從 GKE 工作負載向 API 進行驗證 Google Cloud 」。
授予 trafficdirector.client 角色:
gcloud projects add-iam-policy-binding PROJECT_ID \
--member "group:PROJECT_ID.svc.id.goog:/allAuthenticatedUsers/" \
--role "roles/trafficdirector.client"
啟用 Cloud Service Mesh
將車隊的新成員資格設為預設使用 Gateway API (選用)
或者,您也可以為在叢集建立期間註冊至機群的新 GKE 叢集建立機群層級的預設設定,以便自動設定 Gateway API。
安裝自訂資源定義
為叢集產生 kubeconfig 項目:
gcloud container clusters get-credentials CLUSTER_NAME --location LOCATION --project PROJECT_ID
其中:
安裝 GRPCRoute 自訂資源定義 (CRD):
curl https://raw.githubusercontent.com/kubernetes-sigs/gateway-api/v1.1.0/config/crd/standard/gateway.networking.k8s.io_grpcroutes.yaml \
| kubectl apply -f -
輸出內容類似如下:
customresourcedefinition.apiextensions.k8s.io/grpcroutes.gateway.networking.k8s.io created