简体   繁体   English

如何在负载均衡器后面配置Docker容器?

[英]How Do I Configure Docker Containers Behind A Load Balancer?

My IT infrastructure department has provided me with the following setup: A netscaler load balancer (lb) in front of 3 virtual machines (vm01, vm02, vm03). 我的IT基础架构部门为我提供了以下设置:在3个虚拟机(vm01,vm02,vm03)前面的netscaler负载平衡器(lb)。 Each virtual machine was setup with IIS. 每个虚拟机都使用IIS设置。

I have installed Docker Engine on all three virtual machines and have replicated the same 3 containers (appcontainer1, appcontainer2, appcontainer3) on all 3 virtual machines. 我已经在所有三个虚拟机上安装了Docker Engine,并在所有三个虚拟机上复制了相同的3个容器(appcontainer1,appcontainer2,appcontainer3)。 Each container contains a .NET Core Web API application (api1, api2, api3). 每个容器都包含一个.NET Core Web API应用程序(api1,api2,api3)。

Each container is configured to expose its port 80 for access to the api and is mapped to a port on the virtual machine where it is running. 每个容器都配置为公开其端口80以访问api,并映射到运行该容器的虚拟机上的端口。 In other words appcontainer1 is run with docker run -p 8091:80 . 换句话说,appcontainer1与docker docker run -p 8091:80 .一起docker run -p 8091:80 . , appcontainer2 is run with docker run -p 8092:80 . ,appcontainer2与docker docker run -p 8092:80 .一起docker run -p 8092:80 . , and appcontainer3 is run with docker run -p 8093:80 . ,并且appcontainer3与docker docker run -p 8093:80 .一起docker run -p 8093:80 . .

The problem I am running into is how do I call my web applications from a client machine. 我遇到的问题是如何从客户端计算机调用Web应用程序。 For example, if I wanted to directly call ap1 on vm01 , I would call vm01.domain.com:8091 , but how do I make a call to lb.domain.com:8091 and have it resolve correctly on one of the virtual machines? 例如,如果我想直接在vm01上调用ap1 ,我会调用vm01.domain.com:8091 ,但是如何调用lb.domain.com:8091并使它在其中一个虚拟机上正确解析?

A crudely put together paint drawing of the situation: 粗略汇总了情况的油漆图: 在此处输入图片说明

  • Do I configure the netscaler load balancer to be a reverse proxy and forward the port along to the virtual machines? 是否将netscaler负载均衡器配置为反向代理,并将端口转发到虚拟机?
  • Do I configure a separate DNS entry per application (ap1.domain.com, ap2.domain.com, api3.domain.com) and configure IIS (or nginx or Apache) on each virtual machine to resolve to the appropriate port? 是否在每个应用程序(ap1.domain.com,ap2.domain.com,api3.domain.com)上配置单独的DNS条目,并在每个虚拟机上配置IIS(或nginx或Apache)以解析为适当的端口?
  • Is there a way to configure Docker to do this? 有没有一种方法可以配置Docker来做到这一点?
  • Am I doing it all wrong and over thinking the whole thing? 我是在做错所有事情,还是在思考整个事情吗?
  • Should I be using some sort of container orchestration instead? 我应该改用某种容器编排吗?
  • Is there a sensible way to do this without bothering the infrastructure team to reconfigure everything? 是否有一种明智的方式来做到这一点,而又不会打扰基础架构团队重新配置一切?

You need to setup each IIS on each VM as a reverse proxy with ARR (Application request routing) module. 您需要将每个VM上的每个IIS设置为带有ARR(应用程序请求路由)模块的反向代理。 There are a few tricks that you will use that MAY arise (Hello Microsoft) during this process. 在此过程中,您将使用一些可能会出现的技巧(Microsoft,您好)。 I cannot say anything on the load balancer though. 我在负载均衡器上什么也没说。 Still, it shouldn't be hard to configure it to evenly distribute the load on the machines. 尽管如此,配置它以平均分配机器上的负载并不难。 All you need is to tell LB to direct any call to lb.domain.com:XXXX to one of the VMs in a round robin manner. 您需要做的就是告诉LB以循环方式将对lb.domain.com:XXXX的任何呼叫定向到其中一个VM。 You -probably- can do it to vary the port too, which allows you to have your traffic distributed amongst 3VMs x3containers = 9 containers. 您-可能-也可以更改端口,这使您可以在3VM x3containers = 9个容器之间分配流量。

However, it is recommended not to expose Kestrel server on the net. 但是,建议不要在网络上公开Kestrel服务器。 Instead, put it behind IIS or whatever. 而是将其放在IIS或其他任何后面。 And to configure IIS to act as a reverse proxy, you can either build 3 sites and bind them to the corresponding ports with minimal configuration, or use a single site that uses IIS and resolve the incoming request using rewrite rules. 为了将IIS配置为充当反向代理,您可以构建3个站点并将它们以最少的配置绑定到相应的端口,也可以使用单个站点使用IIS并使用重写规则解决传入的请求。 To be honest IIS is a pain to use with docker. 老实说,IIS是与Docker一起使用的一种痛苦。

BUT what I actually recommend is to use swarm if your OS supports it and expose a single port per VM. 但是 ,我实际上建议您在操作系统支持的情况下使用swarm,并为每个VM公开一个端口。 These are one of: 这些是以下之一:

  • WS2019, WS2019,
  • WS2016 1709 update or later (These have no GUI) WS2016 1709更新或更高版本(这些没有GUI)
  • Windows 10 1709 update. Windows 10 1709更新。

The swarm is still problematic in Windows :/ Also it has very frustrating seemingly random errors involving "localhost:PORT" and stuff. 该群在Windows中仍然是有问题的:/此外,它还具有令人沮丧的看似随机错误,涉及“ localhost:PORT”和其他内容。 For instance, I cannot access my containers on my server (WS2016, pre-1709) using localhost:PORT combination. 例如,我无法使用localhost:PORT组合访问服务器(WS2016,1709之前)上的容器。 Same goes for my development machine (Win10 latest) which has just recently become an issue. 我的开发机器(最新的Win10)也有同样的问题,最近才成为问题。 It was fine before "something" happened and it stopped working. 在“某事”发生并且停止工作之前很好。

If you are flexible about which proxy to use, I recommend taking a look at nginx, Kubernetes and if you are on the experimental side traefik, that allows you to get away without using a container orchestration tool (ie swarm) 如果您对使用哪种代理很灵活,我建议您看一下nginx,Kubernetes,如果您处于实验性traefik方面,那么可以不用使用容器编排工具(例如swarm)就可以逃脱

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

相关问题 在负载均衡器后面滚动部署Docker容器 - rolling deployment for docker containers behind load balancer 如何在ECS中将流利的容器放在负载均衡器后面? - How to put fluentd containers behind a load balancer in ECS? 是否可以为Docker容器定制负载均衡器? - Is a customized load-balancer for Docker containers possible? 如何配置boot2docker在启动时启动容器? - How do I configure boot2docker to start my containers on boot? 如何配置Vert.x事件总线以跨Docker容器群集工作? - How do I configure Vert.x event bus to work across cluster of Docker containers? 如何配置Docker容器代理? - how to configure docker containers proxy? Docker Swarm:绕过负载均衡器并直接向特定容器发出请求 - Docker Swarm: bypass load balancer and make direct request to specific containers 网络和负载均衡器如何在docker swarm模式下工作? - How do networking and load balancer work in docker swarm mode? 如何访问 Docker 容器内容 - How do I access a Docker Containers Contents 我必须使用我的 spring-boot 简单 rest Z72664DC0959F3B0CA9F5EZ 的 docker 容器展示负载均衡器演示 - I have to showcase a load-balancer demo using docker containers of my spring-boot simple rest Api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM