Auto Label¶
- This container puts a label on each machine based on a config that matches service names.
- If the service is running on a node the label gets a 1, and if it isn't the label gets a 0.
- this can be used with constraints to either locate services on a node with another service OR make sure a service doesn't land on a node with another service
I would love to find a better version of this that does this without the need for the manual config file (you can use a file bindmount instead of a config if you prefer)
Swarm Consideration¶
- State is all read-only in a config.
- This runs as one replica on a manager and sets the labels on every node.
- The config is
servicelist.txtin git. It deploys as a swarm config with a version in its name, see stack conventions.
Stack¶
compose.yml, 26 lines, 1 note
each in the code opens a note on that line. download compose.yml
- the service list is
servicelist.txt, below, deployed as a swarm config. swarm refuses a deploy that changes a config's content under the same name, so each change to the list bumps the version suffix on the config's name.
Config¶
- This is the name of the service when running followed by what you want the label to say.
- Use
sudo docker service lsto get the names.
servicelist.txt: each service, and the label it sets, 16 lines
How i use this with adguard to make sure adguard 1 and 2 don't run on the same node EVER (which causes failure conditions)¶
...
adguard2:
...
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.labels.running_adguard1 == 0]
...
This page started as a gist: the original, with its comments