本頁面說明如何設定 Google Kubernetes Engine (GKE) 叢集,以使用 GKE Dataplane V2 可觀測性功能,適用於 GKE 1.28 以上版本。如要進一步瞭解 GKE Dataplane V2 觀測功能的優點和需求,請參閱「關於 GKE Dataplane V2 觀測功能」。
事前準備
開始之前,請確認你已完成下列工作:
- 啟用 Google Kubernetes Engine API。 啟用 Google Kubernetes Engine API
- 如要使用 Google Cloud CLI 執行這項工作,請安裝並初始化 gcloud CLI。如果您先前已安裝 gcloud CLI,請執行
gcloud components update
,取得最新版本。
設定 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。
建立啟用 GKE Dataplane V2 指標的 Autopilot 叢集
建立新的 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 位置。
建立啟用觀測功能的標準叢集
如要建立啟用 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-128.yaml
資訊清單:kubectl apply -f hubble-ui-128.yaml
透過通訊埠轉送公開 Service:
kubectl -n gke-managed-dpv2-observability port-forward service/hubble-ui 16100:80 --address='0.0.0.0'
在網路瀏覽器中存取 Hubble UI: