本頁面說明如何使用 Cloud DNS 設定 Google Kubernetes Engine 叢集範圍。
如要使用 Cloud DNS 設定 GKE 叢集範圍的 DNS 區域,請先選擇現有的私人 DNS 區域,或建立新的私人 DNS 區域,然後將特定 GKE 叢集連結至該區域。接著,設定 DNS 區域以參照 GKE 叢集名稱。
如要進一步瞭解範圍,請參閱「範圍和階層」。
為 GKE 叢集建立私人區域
如要使用 Cloud DNS 為 GKE 叢集建立新的代管不公開區域,請完成下列步驟。
gcloud
執行 gcloud dns managed-zones create
指令:
gcloud dns managed-zones create NAME \ --dns-name=DNS_NAME \ --visibility=private \ --gkeclusters=GKE_CLUSTER
更改下列內容:
NAME
:可用區名稱DNS_NAME
:區域的 DNS 後置字串,例如example.private.
GKE_CLUSTER
:GKE 叢集的完整資源路徑,例如projects/my-project/locations/us-east1a/clusters/my-cluster
API
使用 managedZones.create
方法傳送 POST
要求:
POST https://dns.googleapis.com/dns/v1/projects/PROJECT_ID/managedZones { "name": "NAME", "description": "DESCRIPTION", "dnsName": "DNS_NAME", "visibility": "private" "privateVisibilityConfig": { "kind": "dns#managedZonePrivateVisibilityConfig", "gkeClusters": [{ "kind": "dns#managedZonePrivateVisibilityConfigGKEClusters", "gkeClusterName": GKE_CLUSTER_NAME_1 }, { "kind": "dns#managedZonePrivateVisibilityConfigGKEClusters", "gkeClusterName": GKE_CLUSTER_NAME_2 }, .... ] } }
更改下列內容:
PROJECT_ID
:您建立受管理區的專案 IDNAME
:可用區名稱DESCRIPTION
:區域說明DNS_NAME
:區域的 DNS 後置字串,例如example.private.
GKE_CLUSTER_NAME_1
和GKE_CLUSTER_NAME_2
:GKE 叢集的完整資源路徑,例如projects/my-project/locations/us-east1a/clusters/my-cluster
授權 GKE 叢集查詢 Cloud DNS 私人區域
如要授權 GKE 叢集查詢現有的 Cloud DNS 私人區域,請完成下列步驟。
gcloud
執行 gcloud dns managed-zones update
指令:
gcloud dns managed-zones update NAME \ --gkeclusters=GKE_CLUSTER
更改下列內容:
NAME
:可用區名稱,例如my-zone
GKE_CLUSTER
:GKE 叢集的完整資源路徑,例如projects/my-project/locations/us-east1a/clusters/my-cluster
API
使用 managedZones.patch
方法傳送 PATCH
要求:
PATCH https://dns.googleapis.com/dns/v1/projects/PROJECT_ID/managedZones/NAME { "privateVisibilityConfig": { "gkeClusters": [{ "kind": "dns#managedZonePrivateVisibilityConfigGKEClusters", "gkeClusterName": GKE_CLUSTER_NAME_1 }, { "kind": "dns#managedZonePrivateVisibilityConfigGKEClusters", "gkeClusterName": GKE_CLUSTER_NAME_2 }, .... ] } }
更改下列內容:
PROJECT_ID
:您建立受管理區的專案 IDNAME
:可用區名稱,例如my-zone
GKE_CLUSTER_NAME_1
和GKE_CLUSTER_NAME_2
:GKE 叢集的完整資源路徑,例如projects/my-project/locations/us-east1a/clusters/my-cluster
設定 GKE 叢集以查詢回應政策
如要設定 GKE 叢集以查詢回應政策,請完成下列步驟。
gcloud
執行 gcloud dns response-policies create
指令:
gcloud dns response-policies create NAME \ --description=DESCRIPTION \ --gkeclusters=GKE_CLUSTER
更改下列內容:
NAME
:回應政策的名稱,例如my-response-policy
DESCRIPTION
:回應政策的說明,例如"my-response-policy-for-gke-5"
GKE_CLUSTER
:GKE 叢集的完整資源路徑,例如projects/my-project/locations/us-east1a/clusters/my-cluster
API
使用 responsePolicies.create
方法傳送 POST
要求:
POST https://dns.googleapis.com/dns/v1/projects/PROJECT_ID/responsePolicies { "responsePolicyName": "NAME", "description": "DESCRIPTION", "gkeClusters": [ { "kind": "dns#responsePolicyGKECluster", "gkeClusterName": "GKE_CLUSTER" }, ] }
更改下列內容:
NAME
:回應政策的名稱,例如my-response-policy
DESCRIPTION
:回應政策的說明,例如my-response-policy-for-gke-5
GKE_CLUSTER
:GKE 叢集的完整資源路徑,例如projects/my-project/locations/us-east1a/clusters/my-cluster
後續步驟
- 如要找出使用 Cloud DNS 時可能遇到的常見問題解決方案,請參閱「疑難排解」。
- 如要進一步瞭解 Cloud DNS 回應政策和規則,請參閱「管理回應政策和規則」。
- 如要顯示作業稽核記錄,請參閱「查看代管區域的作業」。