Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Set up anti-affinity for Docker based runtime
Browse files Browse the repository at this point in the history
We've already wired up anti-affinity for containerd based builders
but if you want to distribute images to a multi-node cluster
with docker runtime, having the pods all land on the same node
isn't going to be helpful.
  • Loading branch information
dhiltgen committed Nov 13, 2020
1 parent 8870950 commit ae17ce2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/driver/kubernetes/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func toContainerdWorker(d *appsv1.Deployment, opt *DeploymentOpt) error {
}

func addDockerSockMount(d *appsv1.Deployment, opt *DeploymentOpt) error {
labels := labels(opt)
d.Spec.Template.Spec.Containers[0].VolumeMounts = append(
d.Spec.Template.Spec.Containers[0].VolumeMounts,
corev1.VolumeMount{
Expand All @@ -287,6 +288,23 @@ func addDockerSockMount(d *appsv1.Deployment, opt *DeploymentOpt) error {
},
},
)

// If we're using the dockerd socket to make images available
// on the nodes, we want to distribute the workers across the cluster
// and not let them clump together on a single node
d.Spec.Template.Spec.Affinity = &corev1.Affinity{
PodAntiAffinity: &corev1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []corev1.PodAffinityTerm{
{
LabelSelector: &metav1.LabelSelector{
MatchLabels: labels,
},
TopologyKey: "kubernetes.io/hostname",
},
},
},
}

return nil
}

Expand Down

0 comments on commit ae17ce2

Please sign in to comment.