Affinities help you control where your service runs.
The default scheduling of Kubernetes is enough for most applications. However, in certain use cases, you might want to control where a service runs.
For example, you might prefer that a particular service runs on nodes with SSD. Or that a particular service runs next to another service. This preference is known as affinity.
There are two types of affinities:
For a more in-depth understanding of affinities, you should consider reading this guide from Kubernetes.
In order to specify service affinity, you must first attach labels to the service towards which you have an affinity. By default the following labels are attached to a service deployed by Space Cloud:
app
: {{service.ID}}
version
: {{service.Version}}
app.kubernetes.io/name
: {{service.ID}}
app.kubernetes.io/version
: {{service.ID}}
app.kubernetes.io/managed-by
: space-cloud
space-cloud.io/version
: {{Space Cloud Version}}
Apart from these labels, you can attach custom labels to a service. To attach labels to service, open the Advanced
section of the service configuration and scroll below to the Labels
section:
You can add/edit/delete your labels from here. Click on the Add a label
button to add a label.
Head over to the Deployments
section in Mission Control:
Click on the Edit
button beside the required service to open the service configuration form. Open the Advanced
section and scroll below to the Affinities
section:
Click on the Add
button to add an affinity. You would see the following form:
Configure the following fields to add an affinity:
Weight should be between -100 and 100. Specifying a negative weight implies an anti-affinity.
There are two types of operators:
Kubernetes topology key. Only applicable for affinity type Service
.
Only applicable for affinity type Service
. The projects in which your target service exists.
Match expressions help you describe the affinity towards a group of nodes or services using labels.
Each match expression contains the following fields:
To use affinities, you first need to make sure your nodes/services have appropriate labels so that you can use the match expressions. You can easily manage the labels on your services via Mission Control.