让kubenetes pods相互通信的最好方式是什么? [英] what's the best way to let kubenetes pods communicate with each other?

查看:133
本文介绍了让kubenetes pods相互通信的最好方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个pod,例如一个python网络应用程序和一个redis(由其他应用程序共享),所以我需要将redis放在单独的pod中。但是他们都使用与docker(172.17.0.0/16)相同的子网,甚至使用相同的ip地址。应用程序荚如何与redis pod进行通话?



也许我想要的是什么是设置多主机连接器网络的最佳方式。






7周后,我更熟悉kubernetes。我知道kubernetes有网络假设pod可以互相访问。因此,如果您的应用服务端口需要访问共享服务(redis)pod,则需要将共享服务公开为kubernetes服务,然后可以从应用程序pod的环境变量或主机名获取共享服务端点。

解决方案

当您创建服务时,该服务将代理与不同的pod的连接。



因此,一个服务器维护了pods容器的IP列表。



然后你可以在API中查找那些



他们将在

  http(s):// $ {KUBERNETES_SERVICE_HOST} / api / v1 /命名空间/ $ {NAMESPACE} / endpoints / $ {SERVICE_NAME} 

NAMESPACE是命名空间的名称。默认情况下,它是默认值,所以如果您没有在pod中设置命名空间替换为'default'
SERVICE_NAME是您的服务名称
KUBERNETES_SERVICE_HOST是容器中可用的环境变量。



您将收到带有容器和ip标签的JSON对象。
然后您可以将答案管理到一个

  grep'\ip\'| awk'{print $ 2}'| awk -F\'{print $ 2}'

做隔离IPs



您可能还需要凭据才能到达Google Cloud中的https(用curl测试)
,可以通过查找查找凭据

  gcloud cluster-info< your-cluster-name> 

注意:即使您不使用该服务与您的pod进行通话,也可用于收集您的pod的IP,但是请注意,如果在某个节点重新安排了其他位置,这些可能会改变失败,

该服务负责维护最新的列表,但您的应用程序需要间隔时间间隔或在端点上设置手表以使其列表保持最新。


I have several pods, for example a python web app and a redis(shared by other apps), so I need to place redis in a separate pod. But they are all use the same subnet from docker(172.17.0.0/16) or even the same ip address. how can app pods talk with redis pod?

Maybe what I want ask is what's the best way to setup multi-host conainer networking.


7 weeks later, I get more familiar with kubernetes. I know kubernetes has network assuming that pods can access each other. so if you app service pod need to access a shared service(redis) pod, you need expose the the shared service as a kubernetes service, then you can get the shared service endpoint from app pods' environment variables or hostname.

解决方案

When you create a service, the service will proxy the connection to the different pods.

A service therefore maintains the list of IPs of the pods' containers.

You can then look those up in the API

they will be at

http(s)://${KUBERNETES_SERVICE_HOST}/api/v1/namespaces/${NAMESPACE}/endpoints/${SERVICE_NAME}

NAMESPACE is the name of the namespace. By default it is default, so if you didn't set a namespace in the pod replace with 'default' SERVICE_NAME is your service name KUBERNETES_SERVICE_HOST is an environment variable available in your container.

You will get a JSON object with containers and "ip" tags. You can then pipe the answer to a

grep '\"ip\"' | awk '{print $2}' | awk -F\" '{print $2}' 

do isolate the IPs

You might also need credentials to reach the https (test it with curl) in Google Cloud, credentials can be found by looking up

gcloud cluster-info <your-cluster-name>

Note: even if you don't use the service to talk to your pods, it serves the purpose of gathering the IPs for your pods. However note that these may change if the pod get rescheduled somewhere else when a node fails,
the Service takes care of maintaining the up-to-date list, but your app needs to pull at intervals or set a watch on the endpoints to keep it's list up to date.

这篇关于让kubenetes pods相互通信的最好方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆