[英]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: 粗略汇总了情况的油漆图:
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:
这些是以下之一:
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.