Set cluster DNS correctly in case of nodelocal dns cache (#3879)

* Set cluster DNS correctly in case of nodelocal dns cache

* Pass in cluster_ip based on dns mode

* Disable nodelocaldns by default

* Fix syntax error

* Fix syntax issue

* Add nodelocadns ip to vars of node installation

* Change location of nodelocaldns_ip

* Try to remove newlines from jinja template

* Add debug for config file

* Move parameter logic outside of template

* Adapt templates after feedback

* Remove debugging
pull/4143/head
Thomas Nys 2019-01-29 08:39:27 +01:00 committed by Kubernetes Prow Robot
parent a096761306
commit 68fd7e39da
6 changed files with 41 additions and 31 deletions

View File

@ -122,6 +122,7 @@ dns_mode: coredns
#manual_dns_server: 10.x.x.x #manual_dns_server: 10.x.x.x
# Enable nodelocal dns cache # Enable nodelocal dns cache
enable_nodelocaldns: False enable_nodelocaldns: False
nodelocaldns_ip: 169.254.25.10
# Can be docker_dns, host_resolvconf or none # Can be docker_dns, host_resolvconf or none
resolvconf_mode: docker_dns resolvconf_mode: docker_dns

View File

@ -10,7 +10,6 @@ dns_prevent_single_point_failure: "{{ 'true' if dns_min_replicas|int > 1 else 'f
# nodelocaldns # nodelocaldns
nodelocaldns_cpu_requests: 100m nodelocaldns_cpu_requests: 100m
nodelocaldns_ip: 169.254.25.10
nodelocaldns_memory_limit: 170Mi nodelocaldns_memory_limit: 170Mi
nodelocaldnsdns_memory_requests: 70Mi nodelocaldnsdns_memory_requests: 70Mi

View File

@ -1,4 +1,16 @@
--- ---
- name: Kubernetes Apps | set up necessary nodelocaldns parameters
set_fact:
clusterIP: >-
{%- if dns_mode in ['kubedns', 'coredns', 'coredns_dual'] -%}
{{ skydns_server }}
{%- elif dns_mode == 'dnsmasq_kubedns' -%}
{{ dnsmasq_dns_server }}
{%- elif dns_mode == 'manual' -%}
{{ manual_dns_server }}
{%- endif -%}
secondaryclusterIP: "{{ skydns_server_secondary }}"
- name: Kubernetes Apps | Lay Down nodelocaldns Template - name: Kubernetes Apps | Lay Down nodelocaldns Template
template: template:
src: "{{ item.file }}.j2" src: "{{ item.file }}.j2"
@ -9,8 +21,18 @@
- { name: nodelocaldns, file: nodelocaldns-daemonset.yml, type: daemonset } - { name: nodelocaldns, file: nodelocaldns-daemonset.yml, type: daemonset }
register: nodelocaldns_manifests register: nodelocaldns_manifests
vars: vars:
clusterIP: "{{ skydns_server }}" forwardTarget: >-
secondaryclusterIP: "{{ skydns_server_secondary }}" {%- if secondaryclusterIP is defined and dns_mode == 'coredns_dual' -%}
{{ clusterIP }} {{ secondaryclusterIP }}
{%- else -%}
{{ clusterIP }}
{%- endif -%}
upstreamForwardTarget: >-
{%- if resolvconf_mode == 'host_resolvconf' and upstream_dns_servers is defined and upstream_dns_servers|length > 0 -%}
{{ upstream_dns_servers|join(' ') }}
{%- else -%}
/etc/resolv.conf
{%- endif -%}
when: when:
- enable_nodelocaldns == True - enable_nodelocaldns == True
- inventory_hostname == groups['kube-master'] | first - inventory_hostname == groups['kube-master'] | first

View File

@ -14,58 +14,42 @@ data:
reload reload
loop loop
bind {{ nodelocaldns_ip }} bind {{ nodelocaldns_ip }}
{% if secondaryclusterIP is defined and dns_mode == 'coredns_dual' %} forward . {{ forwardTarget }} {
forward . {{ clusterIP }} {{ secondaryclusterIP }} { force_tcp
{% else %}
forward . {{ clusterIP }} {
{% endif %}
force_tcp
} }
prometheus :9253 prometheus :9253
health {{ nodelocaldns_ip }}:8080 health {{ nodelocaldns_ip }}:8080
} }
in-addr.arpa:53 { in-addr.arpa:53 {
errors errors
cache 30 cache 30
reload reload
loop loop
bind {{ nodelocaldns_ip }} bind {{ nodelocaldns_ip }}
{% if secondaryclusterIP is defined %} forward . {{ forwardTarget }} {
forward . {{ clusterIP }} {{ secondaryclusterIP }} { force_tcp
{% else %}
forward . {{ clusterIP }} {
{% endif %}
force_tcp
} }
prometheus :9253 prometheus :9253
} }
ip6.arpa:53 { ip6.arpa:53 {
errors errors
cache 30 cache 30
reload reload
loop loop
bind {{ nodelocaldns_ip }} bind {{ nodelocaldns_ip }}
{% if secondaryclusterIP is defined %} forward . {{ forwardTarget }} {
forward . {{ clusterIP }} {{ secondaryclusterIP }} { force_tcp
{% else %}
forward . {{ clusterIP }} {
{% endif %}
force_tcp
} }
prometheus :9253 prometheus :9253
} }
.:53 { .:53 {
errors errors
cache 30 cache 30
reload reload
loop loop
bind {{ nodelocaldns_ip }} bind {{ nodelocaldns_ip }}
{% if resolvconf_mode == 'host_resolvconf' and upstream_dns_servers is defined and upstream_dns_servers|length > 0 %} forward . {{ upstreamForwardTarget }} {
forward . {{ upstream_dns_servers|join(' ') }} { force_tcp
{% else %}
forward . /etc/resolv.conf {
{% endif %}
force_tcp
} }
prometheus :9253 prometheus :9253
} }

View File

@ -76,6 +76,9 @@ KUBELET_HOSTNAME="--hostname-override={{ kube_override_hostname }}"
{% else %} {% else %}
{% set kubelet_args_cluster_dns %}{% endset %} {% set kubelet_args_cluster_dns %}{% endset %}
{% endif %} {% endif %}
{% if enable_nodelocaldns == True %}
{% set kubelet_args_cluster_dns %}--cluster-dns={{ nodelocaldns_ip }}{% endset %}
{% endif %}
{% set kubelet_args_dns %}{{ kubelet_args_cluster_dns }} --cluster-domain={{ dns_domain }} --resolv-conf={{ kube_resolv_conf }}{% endset %} {% set kubelet_args_dns %}{{ kubelet_args_cluster_dns }} --cluster-domain={{ dns_domain }} --resolv-conf={{ kube_resolv_conf }}{% endset %}
{# Kubelet node labels #} {# Kubelet node labels #}

View File

@ -57,6 +57,7 @@ dns_mode: coredns
# Enable nodelocal dns cache # Enable nodelocal dns cache
enable_nodelocaldns: False enable_nodelocaldns: False
nodelocaldns_ip: 169.254.25.10
# Should be set to a cluster IP if using a custom cluster DNS # Should be set to a cluster IP if using a custom cluster DNS
# manual_dns_server: 10.x.x.x # manual_dns_server: 10.x.x.x