Service Directory for Google Kubernetes Engine (GKE) 提供您所有 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 检查,以确保客户数据的安全性和隐私性。
- 您可以为 GKE 配置 Service Directory,并使用 Autopilot GKE 集群或 Standard GKE 集群。如需了解这两种模式,请参阅选择 GKE 运维模式。
如需了解如何配置 Service Directory 以自动向 Service Directory 注册 GKE 服务,请参阅为 GKE 配置 Service Directory。
服务映射
向 Service Directory 注册服务时,系统会在 Google Cloud 舰队项目中创建一个服务,该服务使用 Kubernetes 命名空间和 GKE 集群区域的名称。下表介绍了 GKE 服务上的属性如何映射到 Service Directory 中为所有 GKE 服务类型创建的服务上的属性。
顶层属性
| Service Directory 属性 | GKE 属性 |
| 项目 | 舰队项目 |
| 地区 | 集群的区域 |
| 命名空间 | Kubernetes 命名空间 |
LoadBalancer 服务类型
以下示例展示了如何将 GKE LoadBalancer 服务映射到 Service Directory。Service Directory 服务存在于一个命名空间中,该命名空间与舰队项目的 Kubernetes 命名空间和 GKE 集群的区域同名。
| Service Directory 属性 | GKE 属性 |
| 服务名称 | 服务名称 |
| 端点名称 | 由 Service Directory 控制器自动生成 |
| 端点 IP 地址 | LoadBalancer 入口 |
| 端点端口 | LoadBalancer 服务端口 |
| 端点网络 | 集群的 VPC 网络 |
以下是一个 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 地址 | 运行服务的 Pod 的每个节点的节点内部 IP 地址 |
| 端点端口 | 静态节点端口 |
| 端点网络 | 集群的 VPC 网络 |
以下是一个 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 集群的舰队项目和区域中的 Kubernetes 命名空间相同。
| Service Directory 属性 | GKE 属性 |
| 服务名称 | 服务名称 |
| 端点名称 | 由 Service Directory 控制器自动生成 |
| 端点 IP 地址 | ClusterIP |
| 端点端口 | 服务端口 |
| 端点网络 | 集群的 VPC 网络 |
以下是 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 时可能会遇到的常见问题的解决方案,请参阅问题排查。