首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从领事-模板重新加载

从领事-模板重新加载
EN

Stack Overflow用户
提问于 2021-05-10 10:48:12
回答 1查看 556关注 0票数 0

我有多个微服务运行在我的AWS ECS Fargate集群上。在一个任务(pod)中,将有多个容器(一个用于核心业务服务的容器和另外三个侧容器)。以下是这些集装箱的清单:

核心业务服务容器(在特定的port)

  • consul-agent容器上运行核心业务服务(运行领事代理并将其与consul-master)

  • consul-template容器连接)(从领事获取服务信息并更新haproxy.cfg)

  • haproxy容器(从领事模板获取haproxy.cfg并运行)

所有这些集装箱都已投入使用,运行良好。问题是重新加载haproxy。由于领事模板负责更新haproxy.cfg文件,我是否需要在领事模板本身上添加一些配置来更新haproxy?

以下是我当前用于领事模板的命令:

代码语言:javascript
复制
consul-template -consul-addr=xx.xx.xx.xx:8500 -template /etc/consul-template/data/haproxy.cfg.ctmpl:/etc/consul-template/data/haproxy.cfg

我怎样才能做到这一点呢?

EN

回答 1

Stack Overflow用户

发布于 2021-06-17 12:12:12

我目前有完全相同的问题,但对Nginx。

从我的研究来看,没有很好的解决办法。似乎起作用的是装入卷。

代码语言:javascript
复制
-v /var/run/docker.sock:/var/run/docker.sock

在领事-模板容器上。

我看到你在用:

代码语言:javascript
复制
consul-template -consul-addr=xx.xx.xx.xx:8500 -template /etc/consul-template/data/haproxy.cfg.ctmpl:/etc/consul-template/data/haproxy.cfg

为了在领事-模板呈现新的配置文件后运行命令,请使用如下所示:

代码语言:javascript
复制
consul-template -consul-addr=xx.xx.xx.xx:8500 -template /etc/consul-template/data/haproxy.cfg.ctmpl:/etc/consul-template/data/haproxy.cfg:docker run haproxy-container command-to-reload-haproxy

提示

我发现使用领事-模板配置文件更具可读性,语言在这里有很好的说明:https://github.com/hashicorp/consul-template/blob/master/docs/configuration.md

使用这种方法,您将有一个用于领事模板的配置文件(例如consul_template_config.hcl),如下所示:

代码语言:javascript
复制
consul {
  address = "consul-address:8500"
}

template {
  source = "/etc/consul-template/data/haproxy.cfg.ctmpl"
  destination = "/etc/consul-template/data/haproxy.cfg"
  command = "docker run haproxy-container command-to-reload-haproxy"
}

然后,使用以下方法运行领事-模板容器

代码语言:javascript
复制
consul-template -config /path/to/consul_template_config.hcl

或使用

代码语言:javascript
复制
consul-template -config /path/to/folder/containing->consul_template_config.hcl (This approach is more advanced, and lets you have consul-template-configs across multiple files, and not only in 1 like consul_template_config.hcl)

我知道这不是一个很好的解决方案使用这个码头卷(安全警告),但这是我可以找到关于我们的用例。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67469120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档