nginx - 允许在 kubernetes 中与 nginx 进行集群内通信

标签 nginx kubernetes minikube

我当前的 k8s 设置遇到了问题。在生产中,我为每个服务创建了三个副本,并将它们放入一个 pod 中。当 pod 相互交谈时,我们希望 pod 以循环方式与 pod 中的每个容器交谈。不幸的是,由于 TLS 保持事件状态,Pod 之间的连接永远不会终止——我们不想特别改变那部分——但我们确实希望 Pod 中的每个容器都能正确通信。这就是我们现在所拥有的:

How Services Talk

如果 API 试图与 pod OSS 对话,它只会与第一个容器对话。我希望 API 能够以循环方式与所有三个进行对话。

我该怎么做呢?我知道我需要一个入口 Controller ,比如 nginx。但是是否有一些真正的教程可以分解我如何实现这一目标?我不确定并且对 k8s 有点陌生。任何帮助都会受到欢迎!

顺便说一下,我正在本地开发 minikube。

编辑:

在生产中,我们启动每个服务的三个副本。服务时A需要联系服务B ,一个 pod B1来自服务 B被选中并管理它收到的任何请求。然而,那个 pod B1成为服务中唯一的 Pod B处理任何通信;换句话说, pod B2B3从来没有说过。我正在尝试用 nginx 解决这个问题,因为似乎我们需要一个负载平衡器来帮助解决这个问题,但我不知道该怎么做。任何人都可以提供一些关于需要做什么的详细解释吗?具体来说,我如何使用我的服务设置 nginx,以便在一个服务中使用所有 pod(以某种循环方式),这与现在只使用一个 pod 的情况不同?这是一个问题,因为在生产中,当我们有另外两个 pod 坐在那里什么都不做时,一个 pod 会因请求而过载并死亡。我正在 minikube 上进行本地开发。

最佳答案

我假设您的 Pod 下有一个微服务架构,对吗?您是否考虑过使用Istio使用 Kubernetes?它是由 Google、IBM 和 Lyft 开源和开发的——旨在为开发人员提供一种供应商中立的方式(这似乎是您正在寻找的方式)来连接、保护、管理和监控云平台上不同微服务的网络(AWS、Azure、谷歌等)。

At a high level, Istio helps reduce the complexity of these deployments, and eases the strain on your development teams. It is a completely open source service mesh that layers transparently onto existing distributed applications. It is also a platform, including APIs that let it integrate into any logging platform, or telemetry or policy system. Istio’s diverse feature set lets you successfully, and efficiently, run a distributed microservice architecture, and provides a uniform way to secure, connect, and monitor microservices.



这是link to Istio's documentation ,解释如何设置 多集群环境详细说明,这就是您要查找的内容。

文档中有一条我想强调的注释——它可能与您的问题有关:

Since Kubernetes pods don’t have stable IPs, restart of any Istio service pod in the control plane cluster will cause its endpoint to be changed. Therefore, any connection made from remote clusters to that endpoint will be broken. This is documented in Istio issue #4822.

There are a number of ways to either avoid or resolve this scenario. This section provides a high level overview of these options.

  • Update the DNS entries
  • Use a load balancer service type
  • Expose the Istio services via a gateway


我引用了负载平衡器解决方案,因为它似乎是您想要的:

In Kubernetes, you can declare a service with a service type to be LoadBalancer. A simple solution to the pod restart issue is to use load balancers for the Istio services. You can then use the load balancer IPs as the Istio services’s endpoint IPs to configure the remote clusters.



希望能帮到你,有什么问题,就拍吧!

关于nginx - 允许在 kubernetes 中与 nginx 进行集群内通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52065300/

相关文章:

kubernetes - 使用kubernetes批注时出现问题

node.js - Nodemon 使我的 Kubernetes 部署崩溃(导致问题的 Node 模块)

python -/etc/nginx/sites-enabled/django 中的无效参数 server_name

go - 使用自定义 fieldSelector 列出来自缓存客户端的自定义资源

django - 通过 Nginx (Django/React/Nginx/Docker-Compose) 提供 Django 媒体文件

kubernetes - 如何编辑/修补 kubernetes 部署以使用 python 添加标签

docker - 使用Docker的Kubernetes无法从默认端口80更改

reactjs - minikube 中两个 pod 之间的 REST api 调用

linux - Nginx 负载均衡器有两个负载均衡 nginx+php-fpm (主脚本未知)错误

ruby-on-rails-4 - EventSource 调用 ActionController::Live 挂起