From 7e195b06a66f0f4f882924625179772a24d1e892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kr=C3=BCger?= Date: Mon, 8 Oct 2018 16:08:51 +0200 Subject: [PATCH] Fix DNS loop when resolvconf_mode is set to host_resolvconf (#3390) * Fix DNS loop when resolvconf_mode is set to host_resolvconf * Make sure upstream_dns_servers is defined when using resolvconf_mode == 'host_resolvconf' * Only set upstream dns servers on KubeDNS and CoreDNS if they are defined * Only set upstream dns servers on KubeDNS and CoreDNS if they are defined --- docs/vars.md | 2 +- .../ansible/templates/coredns-config.yml.j2 | 8 ++++++++ .../ansible/templates/kubedns-deploy.yml.j2 | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/vars.md b/docs/vars.md index c78708351..a7c6ebccf 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -53,7 +53,7 @@ Kubernetes needs some parameters in order to get deployed. These are the following default cluster paramters: * *cluster_name* - Name of cluster (default is cluster.local) -* *domain_name* - Name of cluster DNS domain (default is cluster.local) +* *dns_domain* - Name of cluster DNS domain (default is cluster.local) * *kube_network_plugin* - Plugin to use for container networking * *kube_service_addresses* - Subnet for cluster IPs (default is 10.233.0.0/18). Must not overlap with kube_pods_subnet diff --git a/roles/kubernetes-apps/ansible/templates/coredns-config.yml.j2 b/roles/kubernetes-apps/ansible/templates/coredns-config.yml.j2 index 34cd4b77e..a89d3fc9e 100644 --- a/roles/kubernetes-apps/ansible/templates/coredns-config.yml.j2 +++ b/roles/kubernetes-apps/ansible/templates/coredns-config.yml.j2 @@ -13,10 +13,18 @@ data: health kubernetes {{ dns_domain }} in-addr.arpa ip6.arpa { pods insecure +{% if resolvconf_mode == 'host_resolvconf' and upstream_dns_servers is defined and upstream_dns_servers|length > 0 %} + upstream {{ upstream_dns_servers|join(' ') }} +{% else %} upstream /etc/resolv.conf +{% endif %} fallthrough in-addr.arpa ip6.arpa } prometheus :9153 +{% if resolvconf_mode == 'host_resolvconf' and upstream_dns_servers is defined and upstream_dns_servers|length > 0 %} + proxy . {{ upstream_dns_servers|join(' ') }} +{% else %} proxy . /etc/resolv.conf +{% endif %} cache 30 } diff --git a/roles/kubernetes-apps/ansible/templates/kubedns-deploy.yml.j2 b/roles/kubernetes-apps/ansible/templates/kubedns-deploy.yml.j2 index e67d3ae37..f6a4c8ff6 100644 --- a/roles/kubernetes-apps/ansible/templates/kubedns-deploy.yml.j2 +++ b/roles/kubernetes-apps/ansible/templates/kubedns-deploy.yml.j2 @@ -97,6 +97,9 @@ spec: - --dns-port=10053 - --config-dir=/kube-dns-config - --v={{ kube_log_level }} +{% if resolvconf_mode == 'host_resolvconf' and upstream_dns_servers is defined and upstream_dns_servers|length > 0 %} + - --nameservers={{ upstream_dns_servers|join(',') }} +{% endif %} env: - name: PROMETHEUS_PORT value: "10055"