7. Placement
Goal: Add a second worker and see how labels and selectors create two hello allocations.
Prerequisites: Chapter 6 — Deploy and changes.
Step 1 — Add a second worker
Edit workspace/workers.json:
[
{
"host": "10.0.0.1",
"labels": ["worker"],
"memory": "4096 mb",
"cpu": "2000 mhz"
},
{
"host": "10.0.0.2",
"labels": ["worker"],
"memory": "4096 mb",
"cpu": "2000 mhz"
}
]
Test SSH and trust the new host:
ssh -i secrets/worker.key agent@10.0.0.2 echo ok
maand worker trust
Step 2 — Build and inspect allocations
maand build
maand cat allocations --jobs hello
You should see two rows: hello on 10.0.0.1 and hello on 10.0.0.2. Build matched job selectors ["worker"] to each worker's labels.
hello job → hello @ 10.0.0.1
→ hello @ 10.0.0.2
To run a job on only some workers, add labels (e.g. "web") to those workers and set "selectors": ["worker", "web"] in the manifest.
Step 3 — Deploy to both workers
maand deploy --jobs hello
Verify both:
maand run_command "hostname && cat /opt/maand/*/jobs/hello/data/status"
Step 4 — Drain one allocation (preview)
To stop hello on one worker without deleting the job definition, use workspace/disabled.json:
{
"jobs": {
"hello": { "allocations": ["10.0.0.2"] }
}
}
Then maand build and maand deploy. The disabled allocation is stopped and not restarted.
Full walkthrough: Guide: disable and drain.
What you learned
- Labels on workers and selectors in the manifest control placement
- One job can have many allocations (one per matching worker)
disabled.jsondrains allocations without removing workspace files
Reference: resources and placement.
Next
Chapter 8 — Go further: pick Guides and Reference for your next task.