问题描述
我目前在ECS服务发现和Route53自动命名方面遇到问题.
I'm currently having an issue with ECS Service Discovery and Route53 Auto Naming.
我已将服务注册表添加到服务中,并且所有托管区域"记录都将自动填充.但是我似乎无法弄清楚如何使用NGINX + ngx_upstream_resolveMK 来解析DNS SRV记录.
I have added the Service Registry to the service and all the Hosted Zones records are being populated automatically.But I cannot seem to work out how to resolve the DNS SRV records with NGINX + ngx_upstream_resolveMK.
# DNS RESOLVER
resolver ns-x.awsdns-xx.com valid=10s;
# UPSTREAMS
upstream kibana {
resolveMK servicediscovery.ecs service=kibana;
}
# HOST - kibana.example.com
server {
server_name kibana.example.com;
listen 80;
location / {
proxy_pass https://kibana/;
rewrite ^/(.*)$ /$1 break;
}
}
错误: nginx:在/usr/local/nginx/sites-enabled/kibana.conf:3
因此,似乎需要缺少A记录才能将"servicediscovery.ecs"解析为Route 53专用区.
So it appears that there is a missing A record needed to resolve "servicediscovery.ecs" to the Route 53 Private Zone.
我需要手动添加吗?还是有办法动态添加此A记录?
Do I need to manually add this? or is there a way to dynamically add this A record?
我认为这是问题的根源,但我仍在学习中,并且可能会遥遥无期.
I think this is the cause of the problem, but I'm still learning and might be way off.
更新:
我阅读了您还可以使用xxx.xxx.xxx.2通过AWS VPC访问DNS我已经使用新的解析器进行了测试,运气不佳.
I read you can also use xxx.xxx.xxx.2 to access the DNS via AWS VPCI have tested using a new resolver without much luck.
# DNS RESOLVER
resolver xxx.xxx.0.2 valid=10s;
推荐答案
当您想在ECS中使用内部DNS时,Nginx会出现问题.
Nginx has a problem using internal DNS when you want use it in ECS.
使用HA-Proxy后我成功了.
I was successful after using HA-Proxy.
它使用Docker的链接"选项,并且HA-Proxy支持使用/etc/hosts
文件.
It uses the "links" option of Docker, and HA-Proxy support uses /etc/hosts
file.
-
首先,使用Docker的链接"选项并设置环境变量"(例如
LINK_APP
,LINK_PORT
).
第二,将这些环境变量"填充到 haproxy.cfg
中.
Second, fill these "environment variables" into haproxy.cfg
.
此外,我建议您使用动态端口映射"到ALB.它使作品更加灵活.
Also, I recommend you use "dynamic port mapping" to ALB. it makes more flexible works.
taskdef.json:
{
"executionRoleArn": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/<APP_NAME>_ecsTaskExecutionRole",
"containerDefinitions": [
{
"name": "<APP_NAME>-rp",
"image": "gnokoheat/ecs-reverse-proxy:latest",
"essential": true,
"memoryReservation": <MEMORY_RESV>,
"portMappings": [
{
"hostPort": 0,
"containerPort": 80,
"protocol": "tcp"
}
],
"links": [
"<APP_NAME>"
],
"environment": [
{
"name": "LINK_PORT",
"value": "<SERVICE_PORT>"
},
{
"name": "LINK_APP",
"value": "<APP_NAME>"
}
]
},
{
"name": "<APP_NAME>",
"image": "<IMAGE_NAME>",
"essential": true,
"memoryReservation": <MEMORY_RESV>,
"portMappings": [
{
"protocol": "tcp",
"containerPort": <SERVICE_PORT>
}
],
"environment": [
{
"name": "PORT",
"value": "<SERVICE_PORT>"
},
{
"name": "APP_NAME",
"value": "<APP_NAME>"
}
]
}
],
"requiresCompatibilities": [
"EC2"
],
"networkMode": "bridge",
"family": "<APP_NAME>"
}
haproxy.cfg:
global
daemon
pidfile /var/run/haproxy.pid
defaults
log global
mode http
retries 3
timeout connect 5000
timeout client 50000
timeout server 50000
frontend http
bind *:80
http-request set-header X-Forwarded-Host %[req.hdr(Host)]
compression algo gzip
compression type text/css text/javascript text/plain application/json application/xml
default_backend app
backend app
server static "${LINK_APP}":"${LINK_PORT}"
Github: https://github.com/gnokoheat/ecs-reverse-proxy
Docker镜像:gnokoheat/ecs-reverse-proxy:latest
Docker image : gnokoheat/ecs-reverse-proxy:latest
这里有更多详细信息解决方案!
这篇关于NGINX反向代理+ ngx_upstream_resolveMK-尝试从ECS服务发现Route53自动命名中解析SRV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!