Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

[v0.13.x] - Allow an AntiAffinty tolerant to help ensure even spread of DNS pods #1672

Merged
merged 4 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions builtin/files/cluster.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,9 @@ kubeDns:
# When enabled, will deploy kube-dns to K8s controllers instead of workers.
# deployToControllers: false

# When enabled, will attempt to deploy kube-dns to nodes in different AZs, useful when autoscaling or deploying to nodes.
# antiAffinityAvailabilityZone: false

# DNS Autoscaler
# Ref: https://github.com/kubernetes-incubator/cluster-proportional-autoscaler/
autoscaler:
Expand Down
17 changes: 15 additions & 2 deletions builtin/files/userdata/cloud-config-controller
Original file line number Diff line number Diff line change
Expand Up @@ -4019,8 +4019,9 @@ write_files:
spec:
priorityClassName: system-node-critical
serviceAccountName: coredns
{{ if .KubeDns.DeployToControllers -}}
{{ if or .KubeDns.DeployToControllers .KubeDns.AntiAffinityAvailabilityZone -}}
affinity:
{{- if .KubeDns.DeployToControllers }}
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
Expand All @@ -4029,7 +4030,19 @@ write_files:
operator: In
values:
- "master"

{{- end }}
{{- if .KubeDns.AntiAffinityAvailabilityZone }}
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
podAffinityTerm:
labelSelector:
- matchExpressions:
- key: k8s-app
operator: In
values:
- "kube-dns"
topologyKey: "failure-domain.beta.kubernetes.io/zone"
{{- end }}
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
Expand Down
9 changes: 5 additions & 4 deletions pkg/api/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ func NewDefaultCluster() *Cluster {
IPVSMode: ipvsMode,
},
KubeDns: KubeDns{
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
TTL: 30,
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
AntiAffinityAvailabilityZone: false,
TTL: 30,
Autoscaler: KubeDnsAutoscaler{
CoresPerReplica: 256,
NodesPerReplica: 16,
Expand Down
13 changes: 7 additions & 6 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ type KubeDnsAutoscaler struct {
}

type KubeDns struct {
Provider string `yaml:"provider"`
NodeLocalResolver bool `yaml:"nodeLocalResolver"`
NodeLocalResolverOptions []string `yaml:"nodeLocalResolverOptions"`
DeployToControllers bool `yaml:"deployToControllers"`
TTL int `yaml:"ttl"`
Autoscaler KubeDnsAutoscaler `yaml:"autoscaler"`
Provider string `yaml:"provider"`
NodeLocalResolver bool `yaml:"nodeLocalResolver"`
NodeLocalResolverOptions []string `yaml:"nodeLocalResolverOptions"`
DeployToControllers bool `yaml:"deployToControllers"`
AntiAffinityAvailabilityZone bool `yaml:"antiAffinityAvailabilityZone"`
TTL int `yaml:"ttl"`
Autoscaler KubeDnsAutoscaler `yaml:"autoscaler"`
}

func (c *KubeDns) MergeIfEmpty(other KubeDns) {
Expand Down
83 changes: 63 additions & 20 deletions pkg/model/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,10 +1119,11 @@ func TestKubeDns(t *testing.T) {
conf: `
`,
kubeDns: api.KubeDns{
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
TTL: 30,
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
AntiAffinityAvailabilityZone: false,
TTL: 30,
Autoscaler: api.KubeDnsAutoscaler{
CoresPerReplica: 256,
NodesPerReplica: 16,
Expand All @@ -1137,10 +1138,49 @@ kubeDns:
deployToControllers: false
`,
kubeDns: api.KubeDns{
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
TTL: 30,
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
AntiAffinityAvailabilityZone: false,
TTL: 30,
Autoscaler: api.KubeDnsAutoscaler{
CoresPerReplica: 256,
NodesPerReplica: 16,
Min: 2,
},
},
},
{
conf: `
kubeDns:
deployToControllers: false
antiAffinityAvailabilityZone: true
`,
kubeDns: api.KubeDns{
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
AntiAffinityAvailabilityZone: true,
TTL: 30,
Autoscaler: api.KubeDnsAutoscaler{
CoresPerReplica: 256,
NodesPerReplica: 16,
Min: 2,
},
},
},
{
conf: `
kubeDns:
deployToControllers: true
antiAffinityAvailabilityZone: true
`,
kubeDns: api.KubeDns{
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: true,
AntiAffinityAvailabilityZone: true,
TTL: 30,
Autoscaler: api.KubeDnsAutoscaler{
CoresPerReplica: 256,
NodesPerReplica: 16,
Expand All @@ -1159,10 +1199,11 @@ kubeDns:
min: 15
`,
kubeDns: api.KubeDns{
Provider: "coredns",
NodeLocalResolver: true,
DeployToControllers: true,
TTL: 30,
Provider: "coredns",
NodeLocalResolver: true,
DeployToControllers: true,
AntiAffinityAvailabilityZone: false,
TTL: 30,
Autoscaler: api.KubeDnsAutoscaler{
CoresPerReplica: 5,
NodesPerReplica: 10,
Expand All @@ -1176,10 +1217,11 @@ kubeDns:
provider: coredns
`,
kubeDns: api.KubeDns{
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
TTL: 30,
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
AntiAffinityAvailabilityZone: false,
TTL: 30,
Autoscaler: api.KubeDnsAutoscaler{
CoresPerReplica: 256,
NodesPerReplica: 16,
Expand All @@ -1194,10 +1236,11 @@ kubeDns:
ttl: 5
`,
kubeDns: api.KubeDns{
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
TTL: 5,
Provider: "coredns",
NodeLocalResolver: false,
DeployToControllers: false,
AntiAffinityAvailabilityZone: false,
TTL: 5,
Autoscaler: api.KubeDnsAutoscaler{
CoresPerReplica: 256,
NodesPerReplica: 16,
Expand Down