When creating services, you can direct the Node(s) to which the containers should be launched based on scheduling rules.
An affinity condition happens when Kontena is trying to find a field that matches (
==) a given value. An anti-affinity condition happens when Kontena is trying to find a field that does not match (
!=) a given value.
affinity: - "<condition 1>" - "<condition N>"
Kontena has the ability to compare values against node name, node labels, service name and container name.
node==node-1will match node with name
node!=node-1will match all nodes, except
label==az=1awill match all nodes with label
label!=az=1awill match all nodes, except nodes with label
service==mysqlwill match all nodes that have instance of service
service!=mysqlwill match all nodes, except those that have instance of service
container==mysql.db-1will match all nodes that have container
container!=mysql.db-1will match all nodes, except those that have container
By default affinities are hard-enforced. If an affinity is not met, the service won't be scheduled. With soft affinity the scheduler tries to meet the rule. If rule is not met, the scheduler will discard the filter and schedule the service according to other filters / deployment strategy.
Soft affinities are expressed with
label==~az-1atries to match nodes with name
node-1. Affinity is discarded if none of the nodes have matching name.
service!=~mysqltries to match nodes which don't have instance of
mysqlservice deployed. Affinity is discarded if all nodes have instance of