Deployment Affinities
When creating services, you can direct the Node(s) to which the containers should be launched based on scheduling rules.
Affinity
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.
For example:
node==node-1
will match node with namenode-1
node!=node-1
will match all nodes, exceptnode-1
label==az=1a
will match all nodes with labelaz=1a
label!=az=1a
will match all nodes, except nodes with labelaz=1a
service==mysql
will match all nodes that have instance of servicemysql
deployedservice!=mysql
will match all nodes, except those that have instance of servicemysql
deployedcontainer==mysql.db-1
will match all nodes that have containermysql.db-1
container!=mysql.db-1
will match all nodes, except those that have containermysql.db-1
Soft Affinity
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 ~
.
For example:
label==~node=node-1
tries to match nodes with namenode-1
. Affinity is discarded if none of the nodes have matching name.service!=~mysql
tries to match nodes which don't have instance ofmysql
service deployed. Affinity is discarded if all nodes have instance ofmysql
service deployed.