Nomad: Difference between revisions
No edit summary |
|||
| Line 35: | Line 35: | ||
|Examine an allocation's logs | |Examine an allocation's logs | ||
|<code>nomad alloc logs allocation-id task-name</code> | |<code>nomad alloc logs allocation-id task-name</code> | ||
|}< | |} | ||
== Concepts == | |||
See: https://learn.hashicorp.com/tutorials/nomad/get-started-vocab?in=nomad/get-started | |||
* '''Task''': Smallest unit of work and is executed by a task driver. Eg. a container running via Docker | |||
* '''Group''': A set of tasks that must run together. Eg. a web server and a database server | |||
* '''Job''': A set of (one or more) groups. Used to constrain the scheduler, set update strategies, ACL | |||
When defining a job, you: | |||
# Specify a job definition | |||
# Within the job, you specify one or more groups | |||
# Within each group, you specify its replica (count=#), task and service | |||
== Installation == | |||
Installation instructions are outlined at https://www.nomadproject.io/docs/install. For CentOS, run: | |||
{{Highlight | |||
| code = # yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo | |||
# yum -y install nomad | |||
| lang = terminal | |||
}} | |||
=== Configuration === | |||
The Nomad configuration file is located at: <code>/etc/nomad.d/nomad.hcl</code>. | |||
{{Highlight | |||
| code = data_dir = "/opt/nomad/data" | |||
bind_addr = "0.0.0.0" | |||
server { | |||
enabled = true | |||
bootstrap_expect = 1 | |||
} | |||
client { | |||
enabled = true | |||
servers = ["127.0.0.1:4646"] | |||
} | |||
| lang = text | |||
}} | |||
But when you start Nomad, you need to specify it with <code>-config</code>: <code>nomad agent -dev-connect -config=/etc/nomad.d/nomad.hcl</code>. You can also specify multiple locations with additional <code>-config</code> parameters. A config path can also be a directory, whereby Nomad will then load all <code>.hcl</code> and <code>.json</code> files within that directory. | |||
Question: Does this file need to be replicated on all member nodes? | |||
==Other== | ==Other== | ||
| Line 43: | Line 86: | ||
Nomad appears to just detect this automatically, like magic. | Nomad appears to just detect this automatically, like magic. | ||
=== | ===Persistent Volumes=== | ||
==== Local Volumes ==== | |||
Volumes local to the host running the task are defined as <code>host_volumes</code>. These are defined within the Nomad configuration within the <code>client</code> stanza/block and requires the Nomad server to be restarted. | |||
Define a <code>host_volume</code> stanza within the client block (https://www.nomadproject.io/docs/configuration/client#host_volume-stanza) in your Nomad configuration file. | |||
{{Highlight | |||
| code = host_volume "mysql" { | |||
path = "/opt/mysql/data" | |||
read_only = false | |||
} | |||
| lang = text | |||
}} | |||
Restart Nomad and then verify that the new host volume shows up when running <code>nomad node status -short -self</code>. | |||
==== Open Questions ==== | |||
*How do I get a container with a persistent volume via NFS? | |||
===Traefik load balancing=== | |||
See: https://learn.hashicorp.com/tutorials/nomad/load-balancing-traefik | |||
Configure Traefik with the <code>consulCatalog</code> provider in the <code>traefik.toml</code> configuration file: | Configure Traefik with the <code>consulCatalog</code> provider in the <code>traefik.toml</code> configuration file: | ||
{{Highlight | {{Highlight | ||
| Line 74: | Line 135: | ||
Traefik will then be notified of the new backends when changes to this service happens via Consul. | Traefik will then be notified of the new backends when changes to this service happens via Consul. | ||
==== Open Questions ==== | ====Open Questions==== | ||
* Can we have the load balancing Traefik instance be an external service? If so, how? | *Can we have the load balancing Traefik instance be an external service? If so, how? | ||
Revision as of 00:58, 16 February 2021
HasiCorp Nomad
Cheat sheet
Allocations are like pods, it contains one or more 'tasks'
Tasks are just containers
Job files contain all the information about the deployment.
| Task | Command |
|---|---|
| Start an agent | nomad agent -dev -bind 0.0.0.0 -log-level INFO
|
| Show node status | nomad node status
|
| Show connected members | nomad server members
|
| Create an example job | nomad job init
|
| Run a job | nomad job run example.nomad
|
| Show a job's status | nomad job status example
|
| Examine an allocation | nomad alloc status allocation-id
|
| Examine an allocation's logs | nomad alloc logs allocation-id task-name
|
Concepts
See: https://learn.hashicorp.com/tutorials/nomad/get-started-vocab?in=nomad/get-started
- Task: Smallest unit of work and is executed by a task driver. Eg. a container running via Docker
- Group: A set of tasks that must run together. Eg. a web server and a database server
- Job: A set of (one or more) groups. Used to constrain the scheduler, set update strategies, ACL
When defining a job, you:
- Specify a job definition
- Within the job, you specify one or more groups
- Within each group, you specify its replica (count=#), task and service
Installation
Installation instructions are outlined at https://www.nomadproject.io/docs/install. For CentOS, run:
# yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
# yum -y install nomad
Configuration
The Nomad configuration file is located at: /etc/nomad.d/nomad.hcl.
data_dir = "/opt/nomad/data"
bind_addr = "0.0.0.0"
server {
enabled = true
bootstrap_expect = 1
}
client {
enabled = true
servers = ["127.0.0.1:4646"]
}
But when you start Nomad, you need to specify it with -config: nomad agent -dev-connect -config=/etc/nomad.d/nomad.hcl. You can also specify multiple locations with additional -config parameters. A config path can also be a directory, whereby Nomad will then load all .hcl and .json files within that directory.
Question: Does this file need to be replicated on all member nodes?
Other
Consul integration
Start consul: consul agent -dev
Nomad appears to just detect this automatically, like magic.
Persistent Volumes
Local Volumes
Volumes local to the host running the task are defined as host_volumes. These are defined within the Nomad configuration within the client stanza/block and requires the Nomad server to be restarted.
Define a host_volume stanza within the client block (https://www.nomadproject.io/docs/configuration/client#host_volume-stanza) in your Nomad configuration file.
host_volume "mysql" {
path = "/opt/mysql/data"
read_only = false
}
Restart Nomad and then verify that the new host volume shows up when running nomad node status -short -self.
Open Questions
- How do I get a container with a persistent volume via NFS?
Traefik load balancing
See: https://learn.hashicorp.com/tutorials/nomad/load-balancing-traefik
Configure Traefik with the consulCatalog provider in the traefik.toml configuration file:
# Enable Consul Catalog configuration backend.
[providers.consulCatalog]
prefix = "traefik"
exposedByDefault = false
[providers.consulCatalog.endpoint]
address = "127.0.0.1:8500"
scheme = "http"
When defining a service within a job in Nomad, specify the following tags:
service {
name = "demo-webapp"
port = "http"
tags = [
"traefik.enable=true",
"traefik.http.routers.http.rule=Path(`/myapp`)",
]
Traefik will then be notified of the new backends when changes to this service happens via Consul.
Open Questions
- Can we have the load balancing Traefik instance be an external service? If so, how?