準備為 Cloud Service Mesh 設定 Gateway API

本頁說明如何在叢集中安裝閘道所需的自訂資源定義。

限制

  • 不支援在同一機群中混用 gateway config-api 和 istio config-api 叢集。請確認機群中所有叢集的 config-api 都設為 gateway。使用 gcloud container fleet mesh describe --project FLEET_PROJECT_ID 指令查看機群的設定。
  • gateway config-api 叢集不支援多叢集服務探索和負載平衡。
  • 如果叢集是使用現有的 --management automatic 旗標上線,叢集就會開始使用 istio 設定 API,且無法變更為 gateway API。
  • 系統僅支援 FQDN。系統不支援簡稱。

資料層管理注意事項

如果是新 Pod,Google 會管理要注入的 Proxy 版本。請注意,受管理資料層會依據 Google Kubernetes Engine (GKE) 發布管道,判斷 Proxy 版本。

如果是現有 Pod,系統會被動管理 Proxy,由叢集中 Pod 的自然生命週期驅動。如要觸發更新並重新注入新版 Proxy,請重新啟動工作負載。

必要條件

本指南假設您已建立 Google Cloud 專案安裝 kubectl

事前準備

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  5. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

建立及註冊 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

其中:

  • CLUSTER_NAME 是叢集名稱
  • LOCATION 是叢集的位置
  • PROJECT_ID 是叢集的專案 ID

控制台

  1. 前往 Google Cloud 控制台的「Google Kubernetes Engine」頁面。

    前往「Google Kubernetes Engine」

  2. 點選 「Create」(建立)

  3. 在「Standard」(標準) 區段中,按一下「Configure」(設定)

  4. 在「叢集基本資訊」部分,完成下列操作:

    1. 輸入叢集的「名稱」
    2. 在「位置類型」中,選取叢集的 Compute Engine 區域
  5. 在導覽窗格中,按一下「節點集區」部分下方的「default-pool」,然後選取「安全性」

  6. 在「Access scopes」(存取權範圍) 清單中,選取「Set access for each API」(針對各個 API 設定存取權),並將「Cloud Platform」(Cloud Platform) 設為「Enabled」(已啟用)

  7. 在導覽窗格中,按一下「叢集」區段下方的「網路」

  8. 在「叢集網路」清單中,選取「啟用 Gateway API」

  9. 在導覽窗格中,按一下「叢集」部分下方的「安全性」

  10. 在「安全性」清單中,選取「啟用 Workload Identity」

  11. 點選「建立」

叢集建立完成後,

  1. 將叢集註冊至機群

    gcloud container fleet memberships register CLUSTER_NAME \
    --gke-cluster LOCATION/CLUSTER_NAME \
    --project=PROJECT_ID
    
  2. 確認叢集已向機群註冊:

    gcloud container fleet memberships list --project=PROJECT_ID
    

    輸出內容類似如下:

    NAME            EXTERNAL_ID                             LOCATION
    my-cluster      91980bb9-593c-4b36-9170-96445c9edd39    us-west1
    

設定權限

請注意,下列指令會將權限授予所有已通過驗證的使用者,但您可以使用 Workload Identity Federation for GKE,只將權限授予特定帳戶。如要瞭解 Workload Identity Federation for GKE 的運作方式,請參閱「關於 Workload Identity Federation for GKE」。如要設定 Workload Identity Federation for 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

  1. 啟用網狀網路功能:

    gcloud container fleet mesh enable --project PROJECT_ID
    
  2. 更新網格以使用 Gateway API:

    gcloud alpha container fleet mesh update \
    --config-api gateway \
    --memberships CLUSTER_NAME \
    --project PROJECT_ID
    
  3. 說明 Cloud Service Mesh 資源的狀態,確認更新:

    gcloud alpha container fleet mesh describe \
    --project PROJECT_ID
    

將車隊的新成員預設為使用 Gateway API (選用)

或者,您也可以為在叢集建立期間註冊至機群的新 GKE 叢集,建立機群層級的預設設定,以便自動設定 Gateway API。

  1. 建立 YAML 檔案,指定使用 Gateway API:

    echo "configapi: gateway" > mesh.yaml
    
  2. 更新網格:

    gcloud alpha container fleet mesh update --project FLEET_PROJECT_ID \
        --fleet-default-member-config mesh.yaml
    
  3. 建立叢集並向機群註冊,即可使用預設設定:

    gcloud container clusters create CLUSTER_NAME \
        --project PROJECT_ID \
        --fleet-project FLEET_PROJECT_ID \
        --location=LOCATION \
    
  4. 啟用 GKE 適用的 Workload Identity Federation,並在節點上執行 GKE 中繼資料伺服器。

安裝自訂資源定義

為叢集產生 kubeconfig 項目:

gcloud container clusters get-credentials CLUSTER_NAME --location LOCATION --project PROJECT_ID

其中:

  • CLUSTER_NAME 是叢集名稱
  • LOCATION 是叢集的位置
  • PROJECT_ID 是叢集的專案 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

後續步驟