Skip to content

Commit

Permalink
Merge pull request #2542 from juanluisvaladas/fix-coredns-affinity
Browse files Browse the repository at this point in the history
Avoid having multiple coredns replicas in the same node
  • Loading branch information
juanluisvaladas authored Dec 23, 2022
2 parents bb33d05 + 7c732d0 commit 70697fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
12 changes: 12 additions & 0 deletions inttest/basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func (s *BasicSuite) TestK0sGetsUp() {
}

s.verifyContainerdDefaultConfig()

s.verifyCoreDNSAntiAffinity(kc)
}

func (s *BasicSuite) checkCertPerms(node string) error {
Expand Down Expand Up @@ -203,6 +205,16 @@ func (s *BasicSuite) verifyContainerdDefaultConfig() {
}).URI(), parsedConfig.Plugins.CRI.SandboxImage)
}

func (s *BasicSuite) verifyCoreDNSAntiAffinity(kc *kubernetes.Clientset) {
opts := metav1.ListOptions{
LabelSelector: "k8s-app=kube-dns",
}
pods, err := kc.CoreV1().Pods("kube-system").List(s.Context(), opts)
s.NoError(err)
s.Equal(2, len(pods.Items))
s.NotEqual(pods.Items[0].Spec.NodeName, pods.Items[1].Spec.NodeName)
}

func TestBasicSuite(t *testing.T) {
s := BasicSuite{
common.FootlooseSuite{
Expand Down
20 changes: 9 additions & 11 deletions pkg/component/controller/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,17 @@ spec:
operator: "Exists"
effect: "NoSchedule"
nodeSelector:
beta.kubernetes.io/os: linux
# Prefer running coredns replicas on different nodes
kubernetes.io/os: linux
# Require running coredns replicas on different nodes
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
topologyKey: "kubernetes.io/hostname"
labelSelector:
matchExpressions:
- key: k8s-app
operator: In
values: ['kube-dns']
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: "kubernetes.io/hostname"
labelSelector:
matchExpressions:
- key: k8s-app
operator: In
values: ['kube-dns']
containers:
- name: coredns
image: {{ .Image }}
Expand Down

0 comments on commit 70697fb

Please sign in to comment.