当前位置:网站首页>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
边栏推荐
- Cloudquery v1.2.0 release
- Unexpected element.. required element
- Detailed software engineering -- the necessary graphs in each stage
- Experiment one
- Qt音视频开发46-视频传输UDP版
- 打工人好物——磨炼钢铁意志就要这样高效的电脑
- Two dimensional code location and alarm system of Expressway
- DC-1 target
- Es create a new index database and copy the old index library, practice pro test effective!
- [elastic search engine]
猜你喜欢
[graffiti Internet of things footprints] panoramic introduction of graffiti cloud platform
[doodling the footprints of Internet of things] Introduction to Internet of things
应用层软件开发教父教你如何重构,资深程序员必备专业技能
Using JSON webtoken (JWT) to generate token in nodejs
How much disk space does a new empty file take?
JVM memory allocation - xms128m - xmx512m - XX: permsize = 128M - XX: maxpermsize = 512M
插件Bilibili新版0.5.5
如何才能快速正确的部署甘特图
New features of vue3
Web API interface design: swaggerui document / unified response format / unified exception handling / unified authority verification
随机推荐
Novice guidance and event management system in game development
Detect certificate expiration script
WebAPI接口设计:SwaggerUI文档 / 统一响应格式 / 统一异常处理 / 统一权限验证
Exclusive interview with Alibaba cloud database for 2020 PostgreSQL Asia Conference: Zeng Wenjing
JVM class loading mechanism
轻量型 GPU 应用首选 京东智联云推出 NVIDIA vGPU 实例
[forward] how to view UserData in Lua
Visual rolling [contrast beauty]
Windows 10 Bluetooth management page 'add Bluetooth or other devices' option click no response solution
Countdown | 2020 PostgreSQL Asia Conference - agenda arrangement of Chinese sub Forum
2020-08-17: how to solve data skew in detail?
ImageMagick - 添加水印
2020 database technology conference helps technology upgrade
Python 100 cases
Epu360: all the H5 templates you want are here, e-book, big turntable, red envelope rain, questionnaire survey
How to write plug-in code of small program mall system? How to use code to check whether the plug-in is successfully added?
2020-08-15: under what circumstances should data tasks be optimized?
Nonvolatile MRAM memory used in all levels of cache
Benefits and functions of auto maintenance app development
2020-09-04: do you understand the function call convention?