From a32671a9cddddf6c7c9c2c4d215a3b577fce3854 Mon Sep 17 00:00:00 2001 From: Dominic Gunn Date: Mon, 17 Jun 2019 14:08:46 +0100 Subject: [PATCH] Configurable coredns ttl --- builtin/files/cluster.yaml.tmpl | 3 +++ .../files/userdata/cloud-config-controller | 3 ++- pkg/api/cluster.go | 1 + pkg/api/types.go | 1 + pkg/model/cluster_test.go | 22 +++++++++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/builtin/files/cluster.yaml.tmpl b/builtin/files/cluster.yaml.tmpl index b7eff80b7..d2ea6acd0 100644 --- a/builtin/files/cluster.yaml.tmpl +++ b/builtin/files/cluster.yaml.tmpl @@ -1328,6 +1328,9 @@ kubeDns: # - --neg-ttl=10 # - --no-ping + # When enabled, will modify the TTL of the coredns service. + # ttl: 30 + # When enabled, will deploy kube-dns to K8s controllers instead of workers. # deployToControllers: false diff --git a/builtin/files/userdata/cloud-config-controller b/builtin/files/userdata/cloud-config-controller index 4cb773e9a..c2878f728 100644 --- a/builtin/files/userdata/cloud-config-controller +++ b/builtin/files/userdata/cloud-config-controller @@ -3784,13 +3784,14 @@ write_files: pods insecure upstream fallthrough in-addr.arpa ip6.arpa + ttl {{ .KubeDns.TTL }} } forward . /etc/resolv.conf { except cluster.local health_check 5s } prometheus :9153 - cache 30 + cache {{ .KubeDns.TTL }} loop reload loadbalance diff --git a/pkg/api/cluster.go b/pkg/api/cluster.go index 1d61f86ab..639b2e5d8 100644 --- a/pkg/api/cluster.go +++ b/pkg/api/cluster.go @@ -154,6 +154,7 @@ func NewDefaultCluster() *Cluster { Provider: "coredns", NodeLocalResolver: false, DeployToControllers: false, + TTL: 30, Autoscaler: KubeDnsAutoscaler{ CoresPerReplica: 256, NodesPerReplica: 16, diff --git a/pkg/api/types.go b/pkg/api/types.go index 4c648dc6d..91f7a253d 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -209,6 +209,7 @@ type KubeDns struct { NodeLocalResolver bool `yaml:"nodeLocalResolver"` NodeLocalResolverOptions []string `yaml:"nodeLocalResolverOptions"` DeployToControllers bool `yaml:"deployToControllers"` + TTL int `yaml:"ttl"` Autoscaler KubeDnsAutoscaler `yaml:"autoscaler"` } diff --git a/pkg/model/cluster_test.go b/pkg/model/cluster_test.go index 1ff319c6e..f71f625f7 100644 --- a/pkg/model/cluster_test.go +++ b/pkg/model/cluster_test.go @@ -1122,6 +1122,7 @@ func TestKubeDns(t *testing.T) { Provider: "coredns", NodeLocalResolver: false, DeployToControllers: false, + TTL: 30, Autoscaler: api.KubeDnsAutoscaler{ CoresPerReplica: 256, NodesPerReplica: 16, @@ -1139,6 +1140,7 @@ kubeDns: Provider: "coredns", NodeLocalResolver: false, DeployToControllers: false, + TTL: 30, Autoscaler: api.KubeDnsAutoscaler{ CoresPerReplica: 256, NodesPerReplica: 16, @@ -1160,6 +1162,7 @@ kubeDns: Provider: "coredns", NodeLocalResolver: true, DeployToControllers: true, + TTL: 30, Autoscaler: api.KubeDnsAutoscaler{ CoresPerReplica: 5, NodesPerReplica: 10, @@ -1176,6 +1179,25 @@ kubeDns: Provider: "coredns", NodeLocalResolver: false, DeployToControllers: false, + TTL: 30, + Autoscaler: api.KubeDnsAutoscaler{ + CoresPerReplica: 256, + NodesPerReplica: 16, + Min: 2, + }, + }, + }, + { + conf: ` +kubeDns: + provider: coredns + ttl: 5 +`, + kubeDns: api.KubeDns{ + Provider: "coredns", + NodeLocalResolver: false, + DeployToControllers: false, + TTL: 5, Autoscaler: api.KubeDnsAutoscaler{ CoresPerReplica: 256, NodesPerReplica: 16,