/
prep-host-dns.yml
67 lines (56 loc) · 2.56 KB
/
prep-host-dns.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
# Copyright 2016, Port.direct, Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This playbook could be made much nicer, and more efficient but doing things
# this way make it easier to parse the hoops jumped through to enable the host
# and pods running in the hosts network namespace to utilise k8s dns effectively
- name: collect kube-dns ip from kubernetes masters
shell: kubectl get --namespace=kube-system svc kube-dns -o jsonpath={.spec.clusterIP}
delegate_to: "{{ item }}"
delegate_facts: true
with_items: "{{ groups['kube-masters'] }}"
register: kube_dns_ip
- name: setting kube-dns ip fact
set_fact:
kube_dns_ip_addr: "{{ item.stdout }}"
with_items: "{{ kube_dns_ip.results }}"
- name: getting current external dns ip from kubernetes masters
shell: cat /etc/resolv.conf | awk '$1 == "nameserver" { print $NF }' | head -n1
delegate_to: "{{ item }}"
delegate_facts: true
with_items: "{{ groups['kube-masters'] }}"
register: external_dns_ip
- name: setting external-dns ip fact
set_fact:
external_dns_ip_addr: "{{ item.stdout }}"
with_items: "{{ external_dns_ip.results }}"
- name: telling network manager to leave resolv.conf alone
shell: sed -i '/\[main\]/adns=none' /etc/NetworkManager/NetworkManager.conf
when: bootstrap_os == "centos"
- name: disabling resolvconf
shell: rm -f /etc/resolv.conf && cp /run/resolvconf/resolv.conf /etc/resolv.conf
when: bootstrap_os == "ubuntu"
# Setup the host's resolve conf to use the k8s dns server
- name: setting up host resolve conf to use kube dns
template: src="resolv.conf.j2" dest="/etc/resolv.conf" mode=0644
- name: restart kubelet
command: systemctl restart kubelet
# This rather ugly step is required to ensure that all pods have the correct resolv.conf
- name: forcing all k8s containers to be recreated with correct dns settings
shell: docker ps | awk '$NF ~ /^k8s_/ { print $1}' | xargs -l1 docker rm -f
ignore_errors: true
- name: waiting for k8s api to come back up
shell: while ! [[ $(kubectl cluster-info) ]]; do sleep 2 ; done
when: inventory_hostname in groups['kube-masters']