準備為 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, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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. 按一下 「建立」。

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

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

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

  6. 在「存取權範圍」清單中,選取「針對各個 API 設定存取權」,並將「Cloud Platform」設為「已啟用」。

  7. 在導覽窗格中,按一下「Networking」(網路)。

  8. 在「負載平衡器、Ingress 和閘道」專區中,選取「啟用 Gateway API」。

  9. 在導覽窗格中,按一下「進階設定」。

  10. 在「Workload identity」(工作負載身分) 列中,確認「Details」(詳細資料) 顯示「Enabled」(已啟用)。如果顯示「已停用」,請按一下 「編輯功能設定」,選取「啟用 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
    

設定權限

請注意,下列指令會將權限授予所有已通過驗證的使用者,但您可以透過 GKE 的 Workload Identity Federation,只將權限授予特定帳戶。如要瞭解 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 適用的工作負載身分聯盟,並在節點上執行 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

後續步驟