当前位置:网站首页>Hamad application scheduling scheme 06 of hashicopy (configure task)
Hamad application scheduling scheme 06 of hashicopy (configure task)
2022-06-11 13:18:00 【Hua Weiyun】
One background
Most applications require some kind of local configuration . Although command line arguments are the simplest method , But many applications need to provide more complex configurations through environment variables or configuration files . This section discusses how to configure Nomad Jobs to support many common configuration use cases .
Two Define application parameters
Many tasks accept configuration through command-line parameters . for example , consider http-echo The server , It's a small go Binary , Render the provided text as a web page . The binary file accepts two parameters :
- listen The flag contains the address to listen on : port
- -text- Present as HTML The text of the page
stay Nomad outside , The server starts like this :
http-echo -listen=":5678" -text="hello world"Nomad Equivalent job documents may be as follows :
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", ] } } }}Be careful : For this job specification , You must be on each client's /bin Folder http-echo.Nomad You can also choose to use artifact resources to get binaries .
Nomad There are many drivers , Most of them support args Parameters pass parameters to their tasks . This parameter also supports Nomad Variable interpolation . for example , If you wish Nomad Dynamically allocate a high port to bind services , Instead of relying on a static port to execute the previous job :
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", ] } } }}3、 ... and Set the environment variable
Some applications can be configured through environment variables . The twelve element application documentation recommends configuring the application through environment variables .Nomad There are two ways to support custom environment variables :
- Interpolation in the environment section
- Templating in the templates section
3.1 env stanza
Each task may have a... That specifies environment variables env section :
task "server" { env { my_key = "my-value" }}env Section also supports interpolation :
task "server" { env { LISTEN_PORT = "${NOMAD_PORT_http}" }}For more information , see also env Section document .
Four Load external configuration file
Many applications use files for configuration .Nomad Supports downloading files using the artifact section , And templating them before starting the task . This allows the transfer of configuration files and other assets necessary for the task to function properly .
Here is a sample job , It pulls down the configuration file as an artifact and templates it :
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", ] } } }}More information about artifact resources , Refer to the artifact section documentation .
Reference link
边栏推荐
- 怎么管理服务器使网站稳定畅通
- Some transformation thoughts of programmers after they are 35 years old
- .net core 抛异常对性能影响的求证之路
- 自定义Terraform-Providers(Terraform Plugin Framework)-04
- Hashicopy之nomad应用编排方案06(配置task)
- 看不懂Kotlin源码?从Contracts 函数说起~
- 關於分布式鎖的續命問題——基於Redis實現的分布式鎖
- 31W contest question bonus! When AI for Science collides with the "pilot Cup", what sparks will be generated?
- Introduction to long connection
- Today in history: Apple II comes out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born
猜你喜欢

长连接简介

Will Apple build a search engine?

关于uni-app 配置 APP 不显示顶部标题栏设置

31w赛题奖金!当 AI for Science 撞上“先导杯”,会擦出什么样的火花?

pip2pi和pypiserver及Apache在pip本地源配置中的应用实践

CS structure and BS structure

@How to resolve controller and requestmapping

The tree (AVL, 2-3-, red black, Huffman)

Today in history: Apple II comes out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born
![[arcgis] City relevance analysis](/img/f4/454266e1ed586240bce9a7f36aa52e.png)
[arcgis] City relevance analysis
随机推荐
Introduction to common fonts
In 2022, capture these 12 data and analyze trends!
看不懂Kotlin源码?从Contracts 函数说起~
从QUIC到TCP
.net core 抛异常对性能影响的求证之路
自定义Terraform-Providers(Terraform Plugin Framework)-04
On software defects and loopholes
漫谈软件缺陷与漏洞
What do you need to do to "surpass" the general database in the time sequence scenario?
The end of an era! After ten years, Wu Enda's classic machine learning course closed its registration this month and launched a new course
Tawang food industry insight | China's dairy market analysis, competition pattern, development trend and thinking
微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!
SAP Spartacus checkout process uses URL paste to directly jump to delivery mode. Why the page cannot be opened
[interface] view the interface path and check the interface
Go 如何减少供应链攻击?
添加环境路径
【backtrader源码解析46】cerebro.py代码注释(枯燥,backtrader核心代码之一,推荐阅读,注释仅供参考)
TeaTalk·Online 演讲实录 | 圆满完结!安全上云,选对数据迁移策略很重要
如何学会花钱
[bug resolution] after uploading the image, cancel the upload and upload again. The last image still exists