本頁面說明如何使用 GKE Dataplane V2 觀測能力,設定 Google Kubernetes Engine (GKE) 叢集 (適用於 GKE 1.32 以上版本)。如要進一步瞭解 GKE Dataplane V2 觀測能力的優點和需求條件,請參閱「關於 GKE Dataplane V2 觀測能力」。
事前準備
開始之前,請確認您已執行下列工作:
- 啟用 Google Kubernetes Engine API。 啟用 Google Kubernetes Engine API
- 如要使用 Google Cloud CLI 執行這項工作,請安裝並初始化 gcloud CLI。如果先前已安裝 gcloud CLI,請執行
gcloud components update指令,取得最新版本。較舊的 gcloud CLI 版本可能不支援執行本文件中的指令。
設定 GKE Dataplane V2 指標
如要收集指標,請設定 GKE Dataplane V2 指標。建立叢集或更新使用 GKE Dataplane V2 執行的叢集時,可以設定 GKE Dataplane V2 指標。您可以使用 gcloud CLI 啟用或停用 GKE Dataplane V2 指標。
建議您在 GKE 叢集上啟用 GKE Dataplane V2 指標和 Google Cloud Managed Service for Prometheus。兩者都啟用後,GKE Dataplane V2 指標就會傳送至 Google Cloud Managed Service for Prometheus。
建立 Autopilot 叢集,並啟用 GKE Dataplane V2 指標
建立新的 GKE Autopilot 叢集時,GKE 預設會啟用叢集的 GKE Dataplane V2 指標,不需使用特定旗標。
如要搭配使用 GKE Autopilot 叢集 GKE Dataplane V2 指標和 Google Cloud Managed Service for Prometheus,請設定 ClusterPodMonitoring 資源,以便抓取指標並傳送至 Google Cloud Managed Service for Prometheus。
建立
ClusterPodMonitoring資訊清單:套用
ClusterPodMonitoring資訊清單:kubectl apply -f ClusterPodMonitoring.yaml
建立已啟用 GKE Dataplane V2 指標的標準叢集
如要啟用 GKE Dataplane V2 指標,請使用 --enable-dataplane-v2-metrics 旗標建立叢集:
gcloud container clusters create CLUSTER_NAME \
--enable-dataplane-v2 \
--enable-ip-alias \
--enable-managed-prometheus \
--enable-dataplane-v2-metrics
更改下列內容:
CLUSTER_NAME:叢集名稱。
--enable-managed-prometheus 旗標會指示 GKE 搭配 Google Cloud Managed Service for Prometheus 使用指標。
在現有叢集啟用 GKE Dataplane V2 指標
如要在現有叢集啟用 GKE Dataplane V2 指標,請執行下列指令:
gcloud container clusters update CLUSTER_NAME \
--enable-dataplane-v2-metrics
將 CLUSTER_NAME 替換為叢集名稱。
停用 GKE Dataplane V2 指標
如要停用 GKE Dataplane V2 指標,請按照下列步驟操作:
gcloud container clusters update CLUSTER_NAME \
--disable-dataplane-v2-metrics
將 CLUSTER_NAME 替換為叢集名稱。
設定 GKE Dataplane V2 觀測工具
您可以使用私人端點,存取 GKE Dataplane V2 觀測能力疑難排解工具。如要啟用 GKE Dataplane V2 觀測能力工具,您必須設定採用 GKE Dataplane V2 的叢集。您可以在新叢集或現有叢集上啟用 GKE Dataplane V2 觀測能力工具。
建立已啟用觀測能力的 Autopilot 叢集
如要建立已啟用 GKE Dataplane V2 觀測能力的 GKE Autopilot 叢集,請按照下列步驟操作:
gcloud container clusters create-auto CLUSTER_NAME \
--enable-dataplane-v2-flow-observability \
--location COMPUTE_LOCATION
替換下列項目:
* CLUSTER_NAME:叢集名稱。COMPUTE_LOCATION:叢集的 Compute Engine 位置。
建立已啟用觀測能力的 Standard 叢集
如要建立啟用 GKE Dataplane V2 觀測能力的 GKE Standard 叢集,請按照下列步驟操作:
gcloud container clusters create CLUSTER_NAME \
--enable-dataplane-v2 \
--enable-ip-alias \
--enable-dataplane-v2-flow-observability \
--location COMPUTE_LOCATION
替換下列項目:
* CLUSTER_NAME:叢集名稱。COMPUTE_LOCATION:叢集的 Compute Engine 位置。
在現有叢集啟用 GKE Dataplane V2 觀測能力工具
如要在現有叢集啟用 GKE Dataplane V2 觀測能力,請執行下列指令:
gcloud container clusters update CLUSTER_NAME \
--enable-dataplane-v2-flow-observability \
--location COMPUTE_LOCATION
更改下列內容:
CLUSTER_NAME:叢集名稱。COMPUTE_LOCATION:叢集的 Compute Engine 位置。
停用 GKE Dataplane V2 觀測能力工具
如要停用現有叢集的 GKE Dataplane V2 觀測工具,請執行下列指令:
gcloud container clusters update CLUSTER_NAME \
--disable-dataplane-v2-flow-observability
將 CLUSTER_NAME 替換為叢集名稱。
如何使用 Hubble CLI
啟用 GKE Dataplane V2 觀測功能後,請在叢集上使用 Hubble CLI 工具。
定義
hubble-cli二進位檔的別名:alias hubble="kubectl exec -it -n gke-managed-dpv2-observability deployment/hubble-relay -c hubble-cli -- hubble"如要檢查 Hubble 狀態,請在啟用 GKE Dataplane V2 觀測功能後,在所有 Autopilot 叢集中使用 Hubble CLI:
hubble status如要查看目前的流量,請按照下列步驟使用 Hubble CLI:
hubble observe
如何部署 Hubble UI 二進位檔發行版本
啟用 GKE Dataplane V2 觀測功能後,即可部署開放原始碼 Hubble UI。
在 GKE 叢集中啟用觀測能力:
建立 GKE 叢集,並啟用觀測能力:
gcloud container clusters create-auto hubble-rc-auto \ --location COMPUTE_LOCATION \ --cluster-version VERSION \ --enable-dataplane-v2-flow-observability更改下列內容:
VERSION:叢集版本。COMPUTE_LOCATION:叢集的 Compute Engine 位置。
或者,您也可以在現有叢集中啟用觀測能力:
gcloud container clusters update CLUSTER_NAME \ --location COMPUTE_LOCATION \ --enable-dataplane-v2-flow-observability更改下列內容:
CLUSTER_NAME:叢集名稱。COMPUTE_LOCATION:叢集的 Compute Engine 位置。
設定
kubectl以連線至叢集:gcloud container clusters get-credentials CLUSTER_NAME \ --location COMPUTE_LOCATION取代
CLUSTER_NAME:叢集名稱。COMPUTE_LOCATION:叢集的 Compute Engine 位置。
部署 Hubble UI:
套用
hubble-ui-132.yaml資訊清單:kubectl apply -f hubble-ui-132.yaml使用通訊埠轉送功能公開 Service:
kubectl -n gke-managed-dpv2-observability port-forward service/hubble-ui 16100:80 --address='0.0.0.0'在網路瀏覽器中存取 Hubble UI: