[英]How can I join a Consul agent to a Consul cluster via a Consul server running in a different Fargate task with CloudFormation?
我目前是实习生,必须托管一个微服务应用程序。 我选择结合使用 AWS ECS 和 Fargate 任务来托管 Consul Connect 服务网格,为应用程序提供服务发现、意图、Mtls 等。 我的设置如下:
我正在使用 CloudFormation 自动部署该基础架构。
问题:
我需要使用 CloudFormation 将在一个 Fargate 任务中运行的 Consul 代理加入到在另一个 Fargate 任务(服务器任务)中启动的 Consul 集群中。 我这样做的问题是我没有找到任何方法来获取 IP 地址以将代理加入集群。
有谁知道我如何获得 CloudFormation 中 Fargate 任务的 IP 地址或执行此操作的最佳实践方式?
如果我没记错的话,您只能使用 IP、DNS 名称或云元数据将 Consul 代理加入 Consul 集群。 第一个和第二个我无法使用 CloudFormation 检索,而第三个我发现它可能是不可能的(我可能是错的,但这就是我到目前为止所读到的)。
我也尝试了 Consul agent -ui [...] -join 和 -retry-join 标志,但都没有工作。 我还尝试使用 Consul 服务器为任务创建内部负载均衡器,我使用 DNS 名称尝试加入集群,但这也不起作用(我还没有在 AWS 上正确设置负载均衡器,所以我可能做错了)。 我尝试使用负载均衡器将流量转发到端口 8500(我认为这是错误的端口),然后使用端口 8301(我认为是正确的端口)。 但我不断收到消息说那个地址上没有 Consul Cluster。
谁能告诉我如何进行?
先感谢您!
感谢我的一位非常聪明的同事,我发现通过 Consul Server Fargate 任务在 ECS 服务前面放置一个负载均衡器(我之前设置错误)解决了我的问题。 负载均衡器侦听器应侦听 SERF 端口 8301 tcp_udp 并将流量转发到具有该协议和端口的服务。
ConsulServerTargetGroup8301:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
HealthCheckEnabled: true
HealthCheckIntervalSeconds: 30
UnhealthyThresholdCount: 3
HealthyThresholdCount: 3
Name: ConsulServerTargetGroup8301
Port: 8301
Protocol: TCP_UDP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 60 # default is 300
TargetType: ip
VpcId: !Ref VPC
ConsulServerTargetGroupListener8301:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- TargetGroupArn: !Ref ConsulServerTargetGroup8301
Type: forward
Port: 8301
Protocol: TCP_UDP
LoadBalancerArn: !Ref ConsulServerLoadbalancer
ConsulServerLoadbalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: ConsulServerLoadbalancer
IpAddressType: ipv4
Type: network
Scheme: internal
SubnetMappings:
- SubnetId: !Ref PrivateSubnet1a
- SubnetId: !Ref PrivateSubnet1b
然后,您可以使用负载均衡器的 DNS 名称将 Consul 代理加入到 consul 集群,方法是:
Command:
- !Sub >-
consul agent
-ui
-data-dir consul/data
-advertise '{{ GetPrivateInterfaces | include "network" "${pVPCIpRange}" | attr "address" }}'
-client 0.0.0.0
-retry-join ${ConsulServerLoadbalancer.DNSName}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.