如何从内部非K8s网络访问K8中的服务?

时间:2016-08-31 07:58:42

标签: google-compute-engine kubernetes google-kubernetes-engine

问题:如何提供从GCE网络中运行的(非K8s)服务到Kubernetes内运行的其他服务的可靠访问?

背景:我们正在 Google云端平台中运行托管的K8s 设置。大多数服务在K8s中 12factor apps 运行只是罚款。一些后备商店(数据库)在K8s 之外运行。通过使用具有手动定义的端点的无头服务来固定内部IP,可以轻松访问它们。这些服务通常不需要与K8中的服务“对话”。

但是在内部GCE网络中运行的某些服务(但在K8s之外)需要访问在K8s中运行的服务。我们可以使用spec.type: NodePort公开K8s服务,并在任何K8s节点IP上与此端口通信。但是,我们如何才能自动找到正确的NodePort和有效的工作节点IP?或者甚至可能有更好的方法来解决这个问题。

此设置可能不是K8s部署的典型用例,但我们希望这样做,直到K8中的PetSet和持久存储已经足够成熟。

在我们讨论内部服务时,我想避免在这种情况下使用外部负载均衡器。

1 个答案:

答案 0 :(得分:2)

You can make cluster service IPs meaningful outside of the cluster (but inside the private network) either by creating a "bastion route" or by running kube-proxy on the machine you are connecting from (see this answer).

I think you could also point your resolv.conf at the cluster's DNS service to be able to resolve service DNS names. This could get tricky if you have multiple clusters though.