Nomad
Nomad
__HTML_TAG_60_ All Commands
Generar PDF
Comandos completos de HashiCorp Nomad y flujos de trabajo para orquestación de carga de trabajo, programación de trabajo y gestión de grupos.
Instalación > Configuración
Command
Description
INLINE_CODE_9
Show Nomad version
INLINE_CODE_10
Start development agent
INLINE_CODE_11
Start with configuration
INLINE_CODE_12
List server members
INLINE_CODE_13
List client nodes
Job Management
Operaciones de trabajo
Command
Description
INLINE_CODE_14
Submit job
INLINE_CODE_15
List all jobs
INLINE_CODE_16
Show job details
INLINE_CODE_17
Stop job
INLINE_CODE_18
Stop and purge job
_
## Job Planning and Validation
Command
Description
---------
-------------
INLINE_CODE_19
Plan job changes
INLINE_CODE_20
Validate job file
INLINE_CODE_21
Inspect job configuration
INLINE_CODE_22
Show job history
_
### Job Scaling
Command
Description
---------
-------------
INLINE_CODE_23
Scale job to 5 instances
INLINE_CODE_24
Scale specific group
_
## Allocation Management
Allocation Operations
Command
Description
INLINE_CODE_25
List allocations
INLINE_CODE_26
Show allocation details
INLINE_CODE_27
Show allocation logs
INLINE_CODE_28
Follow allocation logs
INLINE_CODE_29
Execute command in allocation
_
## Allocation Debugging
Command
Description
---------
-------------
INLINE_CODE_30
List allocation files
INLINE_CODE_31
Read allocation file
INLINE_CODE_32
Restart allocation
INLINE_CODE_33
Stop allocation
Node Management
Node Operations
Command
Description
INLINE_CODE_34
List all nodes
INLINE_CODE_35
Show node details
INLINE_CODE_36
Drain node
INLINE_CODE_37
Disable node scheduling
INLINE_CODE_38
Enable node scheduling
Node Maintenance
Command
Description
INLINE_CODE_39
Drain with deadline
INLINE_CODE_40
Cancel drain
INLINE_CODE_41
Set node metadata
_
## Namespace Management
Command
Description
INLINE_CODE_42
List namespaces
INLINE_CODE_43
Show namespace details
INLINE_CODE_44
Create namespace
INLINE_CODE_45
Delete namespace
ACL Management
ACL Operations
Command
Description
INLINE_CODE_46
Bootstrap ACL system
INLINE_CODE_47
Create token
INLINE_CODE_48
List tokens
INLINE_CODE_49
Show token details
_
## ACL Policies
Command
Description
---------
-------------
INLINE_CODE_50
Create/update policy
INLINE_CODE_51
List policies
INLINE_CODE_52
Show policy details
_
## Monitoring and Debugging
Command
Description
INLINE_CODE_53
List Raft peers
INLINE_CODE_54
Create snapshot
INLINE_CODE_55
Restore snapshot
Monitoring
Command
Description
INLINE_CODE_56
Stream logs
INLINE_CODE_57
Debug level logs
INLINE_CODE_58
Show cluster status
Ejemplos de especificación de empleo
Basic Web Service
job "web" \\\\ {
datacenters = [ "dc1" ]
type = "service"
group "web" \\\\ {
count = 3
network \\\\ {
port "http" \\\\ {
static = 8080
\\\\ }
\\\\ }
service \\\\ {
name = "web"
port = "http"
check \\\\ {
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
\\\\ }
\\\\ }
task "server" \\\\ {
driver = "docker"
config \\\\ {
image = "nginx:latest"
ports = [ "http" ]
\\\\ }
resources \\\\ {
cpu = 100
memory = 128
\\\\ }
\\\\ }
\\\\ }
\\\\ }
Batch Job
job "batch-job" \\\\ {
datacenters = [ "dc1" ]
type = "batch"
group "processing" \\\\ {
count = 1
task "process" \\\\ {
driver = "docker"
config \\\\ {
image = "alpine:latest"
command = "sh"
args = [ "-c", "echo 'Processing data...' && sleep 30" ]
\\\\ }
resources \\\\ {
cpu = 200
memory = 256
\\\\ }
\\\\ }
\\\\ }
\\\\ }
Periodic Job
job "backup" \\\\ {
datacenters = [ "dc1" ]
type = "batch"
periodic \\\\ {
cron = "0 2 * * *"
prohibit_overlap = true
\\\\ }
group "backup" \\\\ {
task "backup-task" \\\\ {
driver = "docker"
config \\\\ {
image = "backup-tool:latest"
command = "/backup.sh"
\\\\ }
resources \\\\ {
cpu = 100
memory = 256
\\\\ }
\\\\ }
\\\\ }
\\\\ }
System Job
job "monitoring" \\\\ {
datacenters = [ "dc1" ]
type = "system"
group "monitoring" \\\\ {
task "node-exporter" \\\\ {
driver = "docker"
config \\\\ {
image = "prom/node-exporter:latest"
network_mode = "host"
pid_mode = "host"
\\\\ }
resources \\\\ {
cpu = 50
memory = 64
\\\\ }
\\\\ }
\\\\ }
\\\\ }
Ejemplos de configuración
Configuración del servidor
datacenter = "dc1"
data_dir = "/opt/nomad/data"
log_level = "INFO"
bind_addr = "0.0.0.0"
server \\\\ {
enabled = true
bootstrap_expect = 3
server_join \\\\ {
retry_join = [ "10.0.1.10", "10.0.1.11", "10.0.1.12" ]
\\\\ }
\\\\ }
consul \\\\ {
address = "127.0.0.1:8500"
\\\\ }
vault \\\\ {
enabled = true
address = "https://vault.service.consul:8200"
\\\\ }
acl \\\\ {
enabled = true
\\\\ }
ui \\\\ {
enabled = true
\\\\ }
Configuración del cliente
datacenter = "dc1"
data_dir = "/opt/nomad/data"
log_level = "INFO"
bind_addr = "0.0.0.0"
client \\\\ {
enabled = true
server_join \\\\ {
retry_join = [ "10.0.1.10", "10.0.1.11", "10.0.1.12" ]
\\\\ }
node_class = "compute"
meta \\\\ {
"type" = "worker"
"zone" = "us-east-1a"
\\\\ }
\\\\ }
plugin "docker" \\\\ {
config \\\\ {
allow_privileged = true
volumes \\\\ {
enabled = true
\\\\ }
\\\\ }
\\\\ }
consul \\\\ {
address = "127.0.0.1:8500"
\\\\ }
vault \\\\ {
enabled = true
address = "https://vault.service.consul:8200"
\\\\ }
Características avanzadas
Constraints and Affinities
job "web" \\\\ {
constraint \\\\ {
attribute = "$\\\\{attr.kernel.name\\\\}"
value = "linux"
\\\\ }
affinity \\\\ {
attribute = "$\\\\{node.class\\\\}"
value = "compute"
weight = 100
\\\\ }
group "web" \\\\ {
constraint \\\\ {
attribute = "$\\\\{meta.zone\\\\}"
value = "us-east-1a"
\\\\ }
# ... rest of group configuration
\\\\ }
\\\\ }
Volume Management
job "database" \\\\ {
group "db" \\\\ {
volume "data" \\\\ {
type = "host"
source = "mysql_data"
read_only = false
\\\\ }
task "mysql" \\\\ {
driver = "docker"
volume_mount \\\\ {
volume = "data"
destination = "/var/lib/mysql"
\\\\ }
config \\\\ {
image = "mysql:8.0"
\\\\ }
\\\\ }
\\\\ }
\\\\ }
Service Discovery Integration
job "api" \\\\ {
group "api" \\\\ {
service \\\\ {
name = "api"
port = "http"
tags = [
"api" ,
"v1.0" ,
"traefik.enable=true" ,
"traefik.http.routers.api.rule=Host(`api.example.com`)"
]
check \\\\ {
type = "http"
path = "/health"
interval = "10s"
timeout = "2s"
\\\\ }
connect \\\\ {
sidecar_service \\\\ {
proxy \\\\ {
upstreams \\\\ {
destination_name = "database"
local_bind_port = 5432
\\\\ }
\\\\ }
\\\\ }
\\\\ }
\\\\ }
\\\\ }
\\\\ }
Buenas prácticas
Job Design
Asignación de recursos : establecer límites adecuados de la CPU y la memoria
** Comprobaciones de salud**: Realizar controles de salud integrales
Graceful Shutdown : Handle SIGTERM signals properly
Logging : Use logging estructurado con niveles adecuados
Configuración : Use plantillas y variables ambientales
Cluster Management
** Alta disponibilidad**: Implementar múltiples nodos de servidor
** Estrategia de respuesta**: instantáneas regulares y copias de seguridad
Monitoreo : Supervisar la salud y el estado de trabajo en racimo
** Planificación de la capacidad**: Plan de recursos necesarios
Seguridad : Habilitar LCA y utilizar TLS
Operations
Rolling Updates : Use estrategias de actualización para cero tiempo de inactividad
Deployments canary : Cambios de prueba con despliegues canarios
** Vigilancia de los recursos**: Supervisar el uso de los recursos
** agregación de log**: centralizar la colección de registros
Alerting : Establecer alertas para cuestiones críticas
Security
Políticas de la Comisión : Implementar el acceso mínimo a los privilegios
Seguridad de red : Use malla de servicio para una comunicación segura
Secrets Management : Integrar con Vault para secretos
** Seguridad de la imagen**: Escaneo imágenes de contenedores para vulnerabilidades
Audit Logging : Activar el registro de auditoría para el cumplimiento