豆荚通讯

Pod Communication

两个不同的 pods 之间的通信在 Kubernetes 中是如何发生的?

在我的例子中,我有两个 pods:frontendbackend,它们都有不同的容器。 我希望我的前端 pod 与后端 pod 通信,但我不想使用后端 pod 的 IP(即硬编码)。

通过服务可以吗?

Is it possible through services?

是,services are the recommended way to handle this. Once you have your services set up for each pod (or replication controller, as is recommended), you can find the service IP via the service environment variable,例如BACKEND_SERVICE_HOSTBACKEND_SERVICE_PORT 用于 "backend" 服务。

推荐的方法是使用 DNS 集群附加组件:http://kubernetes.io/docs/user-guide/services/#dns


来自 'guestbook' 应用程序的示例:

https://github.com/kubernetes/kubernetes/blob/3574999fa34d54c47f43efd9eaff7e1c571c7910/examples/guestbook/php-redis/guestbook.php#L13

他们使用:$host = 'redis-master'; 作为与 redis-master pod 通信的默认方法。

redis-master-service.yaml 中定义:https://github.com/kubernetes/kubernetes/blob/3574999fa34d54c47f43efd9eaff7e1c571c7910/examples/guestbook/redis-master-service.yaml