標準叢集的 Cloud NAT 閘道

Google Distributed Cloud (GDC) 實體隔離方案支援標準叢集,這類叢集是由應用程式運算子群組管理的單一專案自助式 Kubernetes 叢集,可為自訂工作負載提供更大的彈性。本頁面說明如何為標準叢集設定 Cloud NAT,並介紹這類叢集的 NAT 設定限制。

事前準備

設定閘道前,請先取得適當的 Identity and Access Management (IAM) 權限,確保專案具備適當的網路政策,並啟用輸出。

詳情請參閱「開始使用 Cloud NAT 的事前準備」。

Cloud NAT 閘道會使用外部 leaf 子網路做為輸入內容。如要進一步瞭解如何為 Cloud NAT 設定外部子網路,請參閱「為 Cloud NAT 建立外部子網路」。

總覽

圖表:標準叢集的 Cloud NAT 閘道設定

您可以透過兩種方式,設定 Cloud NAT 閘道來處理標準叢集上執行工作負載的輸出流量:

  • 專案範圍的閘道:適用於專案內叢集的所有工作負載流量,包括所有共用和標準叢集。這是「建立 Cloud NAT 閘道」一文所述的設定。
  • 叢集範圍的閘道:僅適用於單一指定標準叢集內的工作負載。這是本頁面示範的閘道類型。

這兩種方法僅適用於工作負載,不適用於構成標準叢集的節點。如要為構成標準叢集的節點啟用 Cloud NAT,請將 cluster.gdc.goog/enable-node-egress-to-outside-the-org: "true" 標籤新增至標準叢集物件。

建立 Cloud NAT 閘道

為標準叢集建立閘道的程序,與建立任何專案範圍的 Cloud NAT 閘道相同。

在本例中,我們著重於標準叢集 Cloud NAT 的叢集篩選功能,並建立類似第一個情境的設定,但會指定標準叢集 user-vc-1 的名稱,端點會透過閘道傳送流量。因此,這個閘道會限定於這個特定叢集。

apiVersion: networking.gdc.goog/v1
kind: CloudNATGateway
metadata:
  namespace: project-1
  name: gateway-1
spec:
  workloadSelector:    # Immutable
    labelSelector:
      workloads:
        matchLabels:
          app: aa
      clusters:
        matchLabels:
          kubernetes.io/metadata.name: user-vc-1
  subnetRefs:           # Mutable
  - subnet-1
  - subnet-2

這項設定會選取標準叢集 user-vc-1 中所有命名空間內,具有 app: aa 標籤的所有工作負載。

檢查閘道狀態

執行下列 kubectl 指令,檢查閘道的狀態。

export MGMT_KUBECONFIG=<path_to_management_kubeconfig>
kubectl get cloudnatgateways gateway-1 -n project-1 --kubeconfig "${MGMT_KUBECONFIG:?}"

如果設定正確,Cloud NAT 閘道的狀態條件欄位應會顯示類型為 Ready 的條件設為 true,且子網路標示為 OK,如下列範例輸出內容所示:

apiVersion: networking.gdc.goog/v1
kind: CloudNATGateway
metadata:
  namespace: project-1
  name: gateway-1
spec:
  workloadSelector:       # Immutable
    labelSelector:
      workloads:
        matchLabels:
          app: aa
      clusters:
        matchLabels:
          kubernetes.io/metadata.name: user-vc-1
  subnetRefs:       # Mutable
  - subnet-1
  - subnet-2
status:
  conditions:
  - lastTransitionTime: "2025-08-20T21:31:36Z"
    message: ""
    observedGeneration: 1
    reason: Ready
    status: "True"
    type: Ready
  - lastTransitionTime: "2025-08-20T21:31:36Z"
    message: ""
    observedGeneration: 1
    reason: Ready
    status: "True"
    type: SubnetsReady
  - lastTransitionTime: "2025-08-20T21:31:36Z"
    message: ""
    observedGeneration: 1
    reason: Ready
    status: "True"
    type: PerimeterConfigurationReady
  - lastTransitionTime: "2025-08-20T21:31:36Z"
    message: ""
    observedGeneration: 1
    reason: Ready
    status: "True"
    type: EgressRoutesReady
  subnets:
  - name: subnet-1
    status: OK
  - name: subnet-2
    status: OK

測試流量

從指派給標準叢集閘道的其中一個 Pod 或 VM,向外部端點發出 curl 指令,測試流量。接收端點應會看到來自與閘道相關聯的其中一個輸出 IP 的封包。共用叢集中具有相同標籤的端點「無法」使用這個閘道輸出流量。

叢集專屬閘道設定的限制

叢集範圍閘道的workloadSelector.labelSelector.workloads.matchLabels工作負載標籤比對器,不得與其他專案範圍閘道的工作負載標籤比對器重疊。如「Cloud NAT 設定限制」一文所述,相同專案和區域中的閘道不得有重疊的 workloadSelector.labelSelector.workloads.matchLabels

Cloud NAT 設定限制中列出的其他限制也適用於叢集範圍閘道設定。