準備為 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. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Kubernetes Engine, GKE Hub, and Cloud Service Mesh APIs.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Kubernetes Engine, GKE Hub, and Cloud Service Mesh APIs.

    Enable the APIs

  8. 建立及註冊 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. 在「標準」部分,按一下「設定」

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

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

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

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

    8. 在「Cluster Networking」(叢集網路) 清單中,選取「Enable Gateway API」(啟用 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
      

    設定權限

    請注意,下列指令會授予所有已驗證使用者權限,但您可以使用 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. 啟用 Workload Identity Federation for 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
    

    後續步驟