当前位置:网站首页>Hashicopy之nomad应用编排方案06(配置task)
Hashicopy之nomad应用编排方案06(配置task)
2022-06-11 13:12:00 【华为云】
一 背景
大多数应用程序需要某种本地配置。虽然命令行参数是最简单的方法,但许多应用程序需要通过环境变量或配置文件提供更复杂的配置。本节探讨如何配置Nomad作业以支持许多常见的配置用例。
二 定义应用参数
许多任务通过命令行参数接受配置。例如,考虑http-echo服务器,它是一个小型go二进制文件,将提供的文本呈现为网页。二进制文件接受两个参数:
- listen标志包含要侦听的地址:端口
- -text-呈现为HTML页面的文本
在Nomad之外,服务器是这样启动的:
http-echo -listen=":5678" -text="hello world"Nomad等效的作业文件可能如下所示:
job "docs" { datacenters = ["dc1"] group "example" { network { port "http" { static = "5678" } } task "server" { driver = "exec" config { command = "/bin/http-echo" args = [ "-listen", ":5678", "-text", "hello world", ] } } }}注意:对于此作业规范,您必须在每个客户端的/bin文件夹中安装http-echo。Nomad还可以选择使用工件资源获取二进制文件。
Nomad有许多驱动程序,大多数都支持通过args参数将参数传递给它们的任务。此参数还支持Nomad变量插值。例如,如果您希望Nomad动态地分配一个高端口来绑定服务,而不是依赖一个静态端口来执行前面的作业:
job "docs" { datacenters = ["dc1"] group "example" { network { port "http" { static = "5678" } } task "server" { driver = "exec" config { command = "/bin/http-echo" args = [ "-listen", ":${NOMAD_PORT_http}", "-text", "hello world", ] } } }}三 设置环境变量
某些应用程序可以通过环境变量进行配置。十二要素应用程序文档建议通过环境变量配置应用程序。Nomad通过两种方式支持自定义环境变量:
- 环境节中的插值
- 在模板节中模板化
3.1 env stanza
每个任务可能有一个指定环境变量的env节:
task "server" { env { my_key = "my-value" }}env节还支持插值:
task "server" { env { LISTEN_PORT = "${NOMAD_PORT_http}" }}有关详细信息,请参阅env节文档。
四 加载外部配置文件
许多应用程序使用文件进行配置。Nomad支持使用工件节下载文件,并在启动任务之前对它们进行模板化。这允许传送任务正常运行所需的配置文件和其他资产。
下面是一个示例作业,它将配置文件作为工件下拉并对其进行模板:
job "docs" { datacenters = ["dc1"] group "example" { task "server" { driver = "exec" artifact { source = "http://example.com/config.hcl.tmpl" destination = "local/config.hcl.tmpl" } template { source = "local/config.hcl.tmpl" destination = "local/config.hcl" } config { command = "my-app" args = [ "-config", "local/config.hcl", ] } } }}有关工件资源的更多信息,请参阅工件节文档。
参考链接
边栏推荐
- Application of "knowing things by learning" behavior time series modeling in the identification of social drainage black production
- 【Multisim仿真】555闪灯实验
- 2022年网上开户是安全的吗?
- [backtrader source code analysis 46] cerebro Py code comments (boring, one of the core backtrader codes, recommended for reading, comments for reference only)
- Which brand of bone conduction Bluetooth headset is good? Five most popular bone conduction Bluetooth headsets
- 【后台交互】select 绑定后台传递的数据
- 怎么管理服务器使网站稳定畅通
- kubernetes 二进制安装(v1.20.15)(六)部署WorkNode节点
- Dbutil auxiliary class, manual commit transaction, metadata
- I am a graduating doctor majoring in mathematics. How should I choose an offer?
猜你喜欢

Dbutil auxiliary class, manual commit transaction, metadata

Unity game protection "big training", read and understand the game's pre defense

Application of "knowing things by learning" behavior time series modeling in the identification of social drainage black production

看不懂Kotlin源码?从Contracts 函数说起~

一个时代的终结!十年了吴恩达经典《机器学习》课程本月关闭注册,上线新课!...

How to write high-performance code (IV) optimize data access

Mctalk's entrepreneurial voice - erudition and discernment: be interested in socializing, and provide a "small and beautiful" space for old friends before and after retirement

About uni app configuration, app does not display the top title bar setting
![[interface] view the interface path and check the interface](/img/b2/8c7645c8f915a9c8cec21bf2937298.png)
[interface] view the interface path and check the interface

马斯克称自己不喜欢做CEO,更想做技术和设计;吴恩达的《机器学习》课程即将关闭注册|极客头条...
随机推荐
[ArcGIS]城市关联度分析
Simple score statistics
After five years of losing the lawsuit, the trillion reptile army is ready to move
The Tree (AVL, 2-3-, 红黑,Huffman)
Does it affect children to wear Bluetooth headsets? How to protect children's ear health
qq内拉起支付宝h5支付功能
Musk says he doesn't like being a CEO, but rather wants to do technology and design; Wu Enda's "machine learning" course is about to close its registration | geek headlines
如何学会花钱
ProblemB. Phoenix and Beauty
From real-time computing to streaming data warehouse, where will Flink go next?
How does Cassandra, an open source database giant, tell a "new story" in China? Face to face
利用 VSCode 的代码模板提高 MobX 的编码效率
字节真的是宇宙尽头吗?
Matrix elimination game
苹果将造搜索引擎?
How can mechanical equipment manufacturing enterprises manage outsourcing with the help of ERP system?
How can non-standard automation equipment manufacturing enterprises achieve rapid and accurate quotation with the help of ERP system?
SQL的语法
Imx6ul development board porting EMMC startup process of mainline u-boot
【信号去噪】基于稀疏性 (BEADS) 实现色谱基线估计和去噪附matlab代码和论文