当前位置:网站首页>confd
confd
2020-11-06 22:33:00 【waynehu】
confd
{{/*
使用lsdir方法,读取(可以认为)/services/web目录下的子目录,也就是返回cust1和cust2这两个。
并开始一个大循环,第1次循环,$dir等于cust1 ,第2次循环,$dir等于cust2
*/}}
{{range $dir := lsdir "/services/web"}}
upstream {{base $dir}} {
{{/*
使用printf方法,合成一个字符串,%s的部分用$dir来替代。
合成之后的新字符串赋值给$custdir,第一次应该是"/services/web/cust1/*"
使用gets查找key为"/services/web/cust1/*"的值,因为用到了*,会查出多个值,所以用到gets而不是get
每个值都会进入小循环,并用json进行解析(这里注意etcdctl put进去的value,必须符合json格式,否则在这里解析会失败)
解析完的内容复制给$data,然后就可以用了
*/}}
{{$custdir := printf "/services/web/%s/*" $dir}}{{range gets $custdir}}
server {{$data := json .Value}}{{$data.IP}}:{{$data.PORT}};
{{end}}
}
server {
server_name {{base $dir}}.example.com;
location / {
proxy_pass {{base $dir}};
}
}
{{end}}
./etcdctl put /services/web/cust1/1 '{"IP": "10.0.0.1","PORT":"81"}'
./etcdctl put /services/web/cust1/2 '{"IP": "10.0.0.2","PORT":"82"}'
./etcdctl put /services/web/cust1/3 '{"IP": "10.0.0.3","PORT":"83"}'
./etcdctl put /services/web/cust2/1 '{"IP": "10.0.0.4","PORT":"84"}'
./etcdctl put /services/web/cust2/2 '{"IP": "10.0.0.5","PORT":"85"}'
./etcdctl put /services/web/cust2/3 '{"IP": "10.0.0.6","PORT":"86"}'
https://github.com/kelseyhightower/confd/blob/master/docs/templates.md
版权声明
本文为[waynehu]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/943306/blog/4706338
边栏推荐
- 应用层软件开发教父教你如何重构,资深程序员必备专业技能
- Big data processing black Technology: revealing the parallel computing technology of Pb level data warehouse gaussdb (DWS)
- Git remote library rollback specified version
- STM32F030C6T6兼容替换MM32SPIN05PF
- August 14, 2020: what are the execution engines for data tasks?
- 2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
- 实验一
- [elastic search engine]
- List to map (split the list according to the key, and the value of the same key is a list)
- How much disk space does a new empty file take?
猜你喜欢
预留电池接口,内置充放电电路及电量计,迅为助力轻松搞定手持应用
The essence of transaction and the principle of deadlock
List to map (split the list according to the key, and the value of the same key is a list)
What kind of music do you need to make for a complete game?
Zhou Jie: database system of East China Normal University
心理咨询app开发所具备的优点与功能
ImageMagick - 添加水印
2020-08-15: under what circumstances should data tasks be optimized?
What grammar is it? ]
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
随机推荐
Introduction to Huawei cloud micro certification examination
The use of Xunwei imx6 development board device tree kernel menuconfig
Message queue - Analysis
Method of code refactoring -- Analysis of method refactoring
Big data processing black Technology: revealing the parallel computing technology of Pb level data warehouse gaussdb (DWS)
The Interpreter pattern of behavior pattern
DC-1 target
2020-08-18:介绍下MR过程?
“非洲用户的付费意愿并不低”——专访四达时代研发总监张亮
JS string - string string object method
汽车维修app开发的好处与功能
Points to be considered when deleting mapping field of index in ES
打工人好物——磨炼钢铁意志就要这样高效的电脑
2020年新规,微信封号怎么快速解除?
vue3 新特性
Configuration of AP hotspot on xunwei-imx6ull development board
What kind of music do you need to make for a complete game?
Common syntax corresponding table of mongodb and SQL
细数软件工程----各阶段必不可少的那些图
JVM class loading mechanism