Service Directory for GKE 總覽

Google Kubernetes Engine (GKE) 適用的 Service Directory 可集中顯示所有 GKE 部署作業中的服務,以及其他服務。您可以新增各種 GKE 服務、為這些服務加上註解,然後在 Service Directory 中查看這些服務。

Service Directory for GKE 提供下列功能:

  • 您可以使用 gRPC 和 HTTP 探索服務,並透過 Service Directory DNS 區域,透過 DNS 解析服務。透過 Service Directory 和 Cloud DNS 整合,您可以設定 Service Directory DNS 區域
  • Service Directory 會註冊 GKE 外部的服務,讓 GKE 和非 GKE 服務輕鬆探索彼此。
  • Service Directory 會強制執行 IAM 權限和 VPC Service Controls 檢查,確保客戶資料的安全性與隱私權。
  • 您可以透過 Autopilot GKE 叢集或 Standard GKE 叢集,設定 Service Directory for GKE。如要瞭解這兩種模式,請參閱「選擇 GKE 作業模式」。

如要瞭解如何設定 Service Directory,以便自動向 Service Directory 註冊 GKE 服務,請參閱「設定適用於 GKE 的 Service Directory」。

服務對應

向 Service Directory 註冊服務時,系統會使用 Kubernetes 命名空間的名稱和 GKE 叢集的區域,在Google Cloud 車隊專案中建立服務。下表說明如何將 GKE 服務的屬性,對應至 Service Directory 中建立的服務屬性 (適用於所有 GKE 服務類型)。

頂層房源

Service Directory 資源 GKE 屬性
專案 機群專案
區域 叢集區域
命名空間 Kubernetes 命名空間

LoadBalancer 服務類型

下列範例說明如何將 GKE LoadBalancer 服務對應至 Service Directory。Service Directory 服務位於命名空間中,該命名空間的名稱與 GKE 叢集的 Fleet 專案和區域中的 Kubernetes 命名空間相同。

Service Directory 資源 GKE 屬性
服務名稱 服務名稱
端點名稱 由 Service Directory 控制器自動產生
端點 IP 位址 LoadBalancer 進入流量
端點通訊埠 LoadBalancer 服務埠
端點網路 叢集的虛擬私有雲網路

以下是 GKE LoadBalancer 服務的範例:

apiVersion: v1
kind: Service
metadata:
  name: hello-app
  annotations:
    cloud.google.com/load-balancer-type: "Internal"
  labels:
    app: hello-app
    sd-import: "true"
spec:
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: hello-app
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 10.140.0.5

以下是 Service Directory 服務的範例:

service:
  endpoints:
  - address: 10.140.0.5
    metadata:
       cloud.google.com/load-balancer-type: "Internal"
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-12345
    port: 80
    network: projects/my-project/locations/global/networks/default
  name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app

NodePort 服務類型

以下範例說明如何將 GKE NodePort 服務對應至 Service Directory。Service Directory 服務位於命名空間中,該命名空間的名稱與 GKE 叢集所在樞紐和區域的專案中,Kubernetes 命名空間的名稱相同。

Service Directory 資源 GKE 屬性
服務名稱 服務名稱
端點名稱 由 Service Directory 控制器自動產生
端點 IP 位址 每個節點的節點內部 IP 位址,這些節點會為服務執行 Pod
端點通訊埠 靜態節點通訊埠
端點網路 叢集的虛擬私有雲網路

以下是 GKE NodePort 服務的範例:

apiVersion: v1
kind: Service
metadata:
  name: hello-app
  annotations:
    key1: "value1"
spec:
  ports:
  - nodePort: 30007
    port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: hello-app
  type: NodePort
  

以下是 GKE 節點的範例:

apiVersion: v1
items:
- apiVersion: v1
  kind: Node
  metadata:
    name: gke-hello-cluster-default-pool-a40cbab6-d2rr
  status:
    addresses:
    - address: 10.142.0.27
      type: InternalIP
    - address: 34.73.248.170
- apiVersion: v1
  kind: Node
  metadata:
    name: gke-hello-cluster-default-pool-a40cbab6-kb38
  status:
    addresses:
    - address: 10.142.0.29
      type: InternalIP
    - address: 35.196.219.215
      type: ExternalIP
- apiVersion: v1
  kind: Node
  metadata:
    name: gke-hello-cluster-default-pool-a40cbab6-x34q
  status:
    addresses:
    - address: 10.142.0.28
      type: InternalIP
    - address: 34.75.202.26
      type: ExternalIP
    

以下是 Service Directory 服務的範例:

service:
  endpoints:
  - address: 10.142.0.27
    metadata:
      key1: value1
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-12345
    port: 30007
    network: projects/my-project/locations/global/networks/default
  - address: 10.142.0.28
    metadata:
      key1: value1
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-23456
    port: 30007
    network: projects/my-project/locations/global/networks/default
  - address: 10.142.0.29
    metadata:
      key1: value1
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-34567
    port: 30007
    network: projects/my-project/locations/global/networks/default
  name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app
  

ClusterIP 項服務

下列範例說明如何將 GKE ClusterIP 服務對應至 Service Directory。Service Directory 服務位於命名空間中,該命名空間與 GKE 叢集的 Fleet 專案和區域中的 Kubernetes 命名空間同名。

Service Directory 資源 GKE 屬性
服務名稱 服務名稱
端點名稱 由 Service Directory 控制器自動產生
端點 IP 位址 ClusterIP
端點通訊埠 服務通訊埠
端點網路 叢集的虛擬私有雲網路

以下是 GKE ClusterIP 服務的範例:

apiVersion: v1
kind: Service
metadata:
  name: hello-app
  annotations:
    key1: "value1"
  labels:
    app: hello-app
    sd-import: "true"
spec:
  clusterIP: 10.15.254.17
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: hello-app
  type: ClusterIP
  

以下是 Service Directory 服務的範例:

service:
  endpoints:
  - address: 10.15.254.17
    metadata:
      key1: value1
    name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app/endpoints/gke-hello-cluster-12345
    port: 80
    network: projects/my-project/locations/global/networks/default
  name: projects/my-project/locations/us-central1/namespaces/default/services/hello-app
  

後續步驟

  • 如要瞭解 Service Directory 總覽,請參閱「Service Directory 總覽」。
  • 如要瞭解使用 Service Directory 時可能遇到的常見問題解決方案,請參閱這篇文章