如何实现Kubernetes POD到POD的通信? [英] How to implement Kubernetes POD to POD Communication?

查看:98
本文介绍了如何实现Kubernetes POD到POD的通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经在stackoverflow上问过并回答过,但是由于我是K8的新手,所以我不明白答案.

This question has been asked and answered before on stackoverflow but because I'm new to K8, I don't understand the answer.

假设我有两个容器,每个容器都放在一个单独的POD中(因为我认为这是推荐的方法),我想我需要为两个容器分开创建一个服务.

Assuming I have two containers with each container in a separate POD (because I believe this is the recommend approach), I think I need to create a single service for my two pods to be apart of.

  1. 我的Java应用程序代码如何获取服务的IP地址?
  2. 我的Java应用程序代码如何(从服务中)获取另一个POD/容器的IP地址?
  3. 这将是IP地址的列表,因为它们是无状态的,并且可能会被复制.这是正确的吗?
  4. 如何选择最不忙的POD实例进行通信?

谢谢 齐格弗里德

推荐答案

我的Java应用程序代码如何获取服务的IP地址?

How does my java application code get the IP address of the service?

您需要创建一个服务来暴露Pod的端口,然后只需要使用服务名称,kube-dns就会解析Pod的IP地址

You need to create a Service to expose the Pod's port and then you just need to use the Service name and kube-dns will resolve the Pod's IP address

我的Java应用程序代码如何获取另一个IP地址 POD/容器(来自服务)?

How does my java application code get the IP addresses of another POD/container (from the service)?

是,使用服务名称

这将是IP地址的列表,因为它们是无状态的,并且它们 可能会被复制.这是正确的吗?

This will be a list of IP address because these are stateless and they might be replicated. Is this correct?

该服务将在与选择器匹配的所有Pod之间进行负载平衡,因此它可以是0、1或任意数量的Pod

The Service will load balance between all pods that matches the selector, so it could be 0, 1 or any number of Pods

如何选择最不忙的POD实例进行通信?

How do I select the least busy instance of the POD to communicate with?

常见方法是循环策略,但是这里有其他特定的平衡策略 https://kubernetes.io/docs/concepts/services -networking/service/#proxy-mode-ipvs

Common way is round robin policy but here are other specific balancing policies https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs

干杯;)

这篇关于如何实现Kubernetes POD到POD的通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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