简体   繁体   English

Kubernetes:获取网络上其他Pod的IP地址

[英]Kubernetes: Getting the IP Addresses of Other Pods on the Network

What's the best way to get the IP addresses of the other kubernetes pods on a local network? 在本地网络上获取其他Kubernetes Pod的IP地址的最佳方法是什么?

Currently, I'm using the following command and parsing the output: kubectl describe pods . 当前,我正在使用以下命令并解析输出: kubectl describe pods

Unfortunately, the command above often takes many seconds to complete (at least 3, and often 30+ seconds) and if a number of requests happen nearly simultaneously, I get 503 style errors. 不幸的是,上面的命令通常需要花费几秒钟来完成(至少需要3秒钟,通常至少需要30秒钟以上),并且如果多个请求几乎同时发生,则会收到503个样式错误。 I've built a caching system around this command to cache the IP addresses on the local pod, but when a 10 or so pods wake up and need to create this cache, there is a large delay and often many errors. 我围绕此命令构建了一个缓存系统,用于在本地Pod上缓存IP地址,但是当大约10个Pod醒来并需要创建此缓存时,会有很大的延迟,并且经常会出现许多错误。 I feel like I'm doing something wrong. 我觉得我做错了什么。 Getting the IP addresses of other pods on a network seems like it should be a straightforward process. 获取网络上其他Pod的IP地址似乎应该是一个简单的过程。 So what's the best way to get them? 那么获得它们的最佳方法是什么?

For added details, I'm using Google's kubernetes system on their container engine. 有关更多详细信息,我在其容器引擎上使用了Google的kubernetes系统。 Running a standard Ubuntu image. 运行标准的Ubuntu映像。


Context : To add context, I'm trying to put together a shared memcached between the pods on the cluster. 上下文 :要添加上下文,我正在尝试在群集的Pod之间放一个共享的内存缓存。 To do that, they all need to know eachother's IP address. 为此,他们都需要知道彼此的IP地址。 If there's an easier way to link pods/instances for the purposes of memcached, that would also be helpful. 如果有一种更简单的方法可以出于内存缓存的目的来链接容器/实例,那也将有所帮助。

Have you tried 你有没有尝试过

kubectl get pods -o wide

This also returns IP addresses of the pods. 这还会返回容器的IP地址。 Since this does not return ALL information describe returns, this might be faster. 由于这不会返回所有describe返回的信息,因此可能更快。

For your described use case you should be using services. 对于描述的用例,您应该使用服务。 A headless service would allow you to reference them with my-svc.my-namespace.svc.cluster.local . 无头服务将允许您使用my-svc.my-namespace.svc.cluster.local引用它们。 This assumes you don't need to know individual nodes, only how to reach one of them, as it will round robin between them. 假设您不需要知道单个节点,只需知道如何到达其中一个节点,因为它将在它们之间循环。

If you do need to have fixed network identities in your cluster attached to the pods you can setup a StatefulSet and reference them with: app-0.my-svc.my-namespace.svc.cluster.local , app-1.my-svc.my-namespace.svc.cluster.local and so on. 如果您确实需要将群集中的固定网络身份附加到Pod,则可以设置一个StatefulSet并使用以下内容引用它们: app-0.my-svc.my-namespace.svc.cluster.localapp-1.my-svc.my-namespace.svc.cluster.local等。

You should never need to contact specific pod ip's in other ways, specially since they can be rescheduled at any time and have their IPs changed. 您永远不需要以其他方式联系特定的Pod ip,尤其是因为可以随时重新安排它们的IP并更改其IP。

For your use case specifically, it might be easier to just use the memcache helm chart, which supports a cluster in a StatefulSet: https://github.com/kubernetes/charts/tree/master/stable/memcached 对于您的用例而言,仅使用memcache舵图可能更容易,该舵图支持StatefulSet中的集群: https : //github.com/kubernetes/charts/tree/master/stable/memcached

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kubernetes Pod与内部/外部IP地址的互通 - Kubernetes Pods intercommunication with internal/external IP addresses 如何设置 kubernetes 服务和 pod 的 IP 地址和端口以将一些信息发送到 pod? - How would I set up kubernetes Services and pods' IP addresses and ports to send some information into a pod? Kubernetes-单个Pod的可路由IP - Kubernetes - Routable IP to individual Pods 如何获取docker网络上的所有IP地址? - How to get all ip addresses on a docker network? 如何在应用程序内部使用Kubernetes Pod或部署IP - How to get kubernetes pods or deployment IP to be used inside application 各种 Minikube + Kubernetes IP 地址有什么区别? - What's the difference between various Minikube + Kubernetes IP addresses? 如何在 kubernetes 中向其他 pod 公开服务? - How can I expose a service to other pods in kubernetes? 来自docker inspect的jq bash命令的网络IP地址 - Network IP addresses with jq bash command from docker inspect 在创建 Kubernetes pod 时在 EC2 实例上获取 ImagePullBackOff - Getting ImagePullBackOff on EC2 instance while creating Kubernetes pods kubeadm kubedns错误。 无法访问外部网络或其他Pod - kubeadm kubedns error. could not access external network or other pods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM