這個頁面說明如何使用 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-zoneGKE_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-zoneGKE_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-policyDESCRIPTION:回應政策的說明,例如"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-policyDESCRIPTION:回應政策的說明,例如my-response-policy-for-gke-5GKE_CLUSTER:GKE 叢集的完整資源路徑,例如projects/my-project/locations/us-east1a/clusters/my-cluster
後續步驟
- 如需解決 Cloud DNS 的常見使用問題,請參閱這篇文章。
- 如要進一步瞭解 Cloud DNS 回應政策和規則,請參閱「管理回應政策和規則」。
- 如要顯示作業的稽核記錄,請參閱「查看代管區域的作業」。