当前位置:网站首页>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", ] } } }}有关工件资源的更多信息,请参阅工件节文档。
参考链接
边栏推荐
- In 2022, capture these 12 data and analyze trends!
- About uni app configuration, app does not display the top title bar setting
- 详解C语言实参与形参的区别
- 【Multisim仿真】555闪灯实验
- Quic resistance
- Dbutil auxiliary class, manual commit transaction, metadata
- . 5 string
- In the list of 618 projector hedging brands in 2022, dangbei projection ranked top 1 in the hedging rate of idle fish
- Zhongfu Jinshi: with the rapid development of the intelligent bathroom industry, the intelligent toilet will usher in a highlight moment
- kubernetes 二进制安装(v1.20.16)(五)验证 master 部署
猜你喜欢

Dbutil auxiliary class, manual commit transaction, metadata

CS structure and BS structure

Is Zhima Z1 projector really easy to use? How about the actual effect?

Stone technology: R & D strength and excellent quality help upgrade the sweeping robot industry

Schéma de dessin utilisé par les Pads

【接口】看接口路径 查接口

Audio adaptation of openharmony Standard System Porting

PADS使用之繪制原理圖

逆向学习入门-优秀的汇编调试工具OllyDbg

网络信息系统应急响应
随机推荐
一个时代的终结!十年了吴恩达经典《机器学习》课程本月关闭注册,上线新课!...
kubernetes 证书合集
启牛商学院给的券商账户是安全的吗?开户收费吗
Zhongfu Jinshi: with the rapid development of the intelligent bathroom industry, the intelligent toilet will usher in a highlight moment
Which brand of bone conduction Bluetooth headset is good? Five most popular bone conduction Bluetooth headsets
[arcgis] City relevance analysis
Is it safe to open an account online in 2022?
2022 年,捕捉这 12 个数据和分析趋势!
深度学习与CV教程(14) | 图像分割 (FCN,SegNet,U-Net,PSPNet,DeepLab,RefineNet)
. The way to prove the effect of throwing exceptions on performance in. Net core
求你了,不要再在对外接口中使用枚举类型了!
[problem summary] $t
關於分布式鎖的續命問題——基於Redis實現的分布式鎖
字节真的是宇宙尽头吗?
tf.data(二) —— 并行化 tf.data.Dataset 生成器
刚高考完有些迷茫不知道做些什么?谈一谈我的看法
Teatalk · online speech record | complete! It is important to select the right data migration strategy for safe cloud deployment
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
如何写出高性能代码(四)优化数据访问
Microsoft exposes another "scandal": watching VR porn in the office, "the father of hololens" is about to leave!