From 7b8ed5a12cea1286be1fc684d93f23933c8c80c3 Mon Sep 17 00:00:00 2001 From: Jeff Bean Date: Wed, 17 Jun 2015 19:00:27 -0400 Subject: [PATCH] support dns in particular --- contrib/ansible/cluster.yml | 5 +- contrib/ansible/group_vars/all.yml | 19 +++++++ .../roles/kubernetes-addons/tasks/dns.yml | 55 +++++++++++++++++++ .../roles/kubernetes-addons/tasks/main.yml | 6 +- .../ansible/roles/node/templates/kubelet.j2 | 4 ++ 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 contrib/ansible/roles/kubernetes-addons/tasks/dns.yml diff --git a/contrib/ansible/cluster.yml b/contrib/ansible/cluster.yml index 52a8bf35cf..6454c2f8d1 100644 --- a/contrib/ansible/cluster.yml +++ b/contrib/ansible/cluster.yml @@ -33,9 +33,10 @@ - hosts: masters sudo: yes roles: - - kubernetes-addons + - kubernetes-addons tags: - - addons + - addons + - dns # install kubernetes on the nodes - hosts: nodes diff --git a/contrib/ansible/group_vars/all.yml b/contrib/ansible/group_vars/all.yml index b4a087c705..413c4d2241 100644 --- a/contrib/ansible/group_vars/all.yml +++ b/contrib/ansible/group_vars/all.yml @@ -42,3 +42,22 @@ flannel_prefix: 12 # will give to each node on your network. With these defaults you should have # room for 4096 nodes with 254 pods per node. flannel_host_prefix: 24 + +# Turn this varable to 'false' to disable whole DNS configuration. +dns_setup: true +# How many replicas in the Replication Controller +dns_replicas: 1 + +# Internal DNS domain name. +# This domain must not be used in your network. Services will be discoverable +# under .., e.g. +# myservice.default.kube.local +dns_domain: kube.local + +# IP address of the DNS server. +# Kubernetes will create a pod with several containers, serving as the DNS +# server and expose it under this IP address. The IP address must be from +# the range specified as kube_service_addresses above. +# And this is the IP address you should use as address of the DNS server +# in your containers. +dns_server: 10.254.0.10 diff --git a/contrib/ansible/roles/kubernetes-addons/tasks/dns.yml b/contrib/ansible/roles/kubernetes-addons/tasks/dns.yml new file mode 100644 index 0000000000..a2e264c7b6 --- /dev/null +++ b/contrib/ansible/roles/kubernetes-addons/tasks/dns.yml @@ -0,0 +1,55 @@ +--- +- name: DNS | Assures {{ kube_config_dir }}/addons/dns dir exists + file: path={{ kube_config_dir }}/addons/dns state=directory + +- name: DNS | Assures local dns addon dir exists + local_action: file + path={{ local_temp_addon_dir }}/dns + state=directory + sudo: no + +- name: DNS | Download skydns-rc.yaml file from Kubernetes repo + local_action: get_url + url=https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes/master/cluster/addons/dns/skydns-rc.yaml.in + dest="{{ local_temp_addon_dir }}/dns/skydns-rc.yaml.j2" + force=yes + sudo: no + +- name: DNS | Convert pillar vars to ansible vars for skydns-rc.yaml + local_action: replace + dest="{{ local_temp_addon_dir }}/dns/skydns-rc.yaml.j2" + regexp="pillar\[\'(\w*)\'\]" + replace="\1" + sudo: no + +- name: DNS | Install Template from converted saltfile + template: + args: + src: "{{ local_temp_addon_dir }}/dns/skydns-rc.yaml.j2" + dest: "{{ kube_config_dir }}/addons/dns/skydns-rc.yaml" + mode: 0755 + owner: root + group: root + +- name: DNS | Download skydns-svc.yaml file from Kubernetes repo + local_action: get_url + url=https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes/master/cluster/addons/dns/skydns-svc.yaml.in + dest="{{ local_temp_addon_dir }}/dns/skydns-svc.yaml.j2" + force=yes + sudo: no + +- name: DNS | Convert pillar vars to ansible vars for skydns-rc.yaml + local_action: replace + dest="{{ local_temp_addon_dir }}/dns/skydns-svc.yaml.j2" + regexp="pillar\[\'(\w*)\'\]" + replace="\1" + sudo: no + +- name: DNS | Install Template from converted saltfile + template: + args: + src: "{{ local_temp_addon_dir }}/dns/skydns-svc.yaml.j2" + dest: "{{ kube_config_dir }}/addons/dns/skydns-svc.yaml" + mode: 0755 + owner: root + group: root diff --git a/contrib/ansible/roles/kubernetes-addons/tasks/main.yml b/contrib/ansible/roles/kubernetes-addons/tasks/main.yml index cf5482660f..3da6617954 100644 --- a/contrib/ansible/roles/kubernetes-addons/tasks/main.yml +++ b/contrib/ansible/roles/kubernetes-addons/tasks/main.yml @@ -11,6 +11,10 @@ state=directory sudo: no +- include: dns.yml + when: dns_setup + tags: dns + #- name: Get kube-addons script from Kubernetes # get_url: # url=https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes/master/cluster/saltbase/salt/kube-addons/kube-addons.sh @@ -37,7 +41,7 @@ environment: TOKEN_DIR: "{{ kube_config_dir }}" with_items: - - + - "system:dns" register: gentoken changed_when: "'Added' in gentoken.stdout" notify: diff --git a/contrib/ansible/roles/node/templates/kubelet.j2 b/contrib/ansible/roles/node/templates/kubelet.j2 index d7937bdf67..953e5e05fb 100644 --- a/contrib/ansible/roles/node/templates/kubelet.j2 +++ b/contrib/ansible/roles/node/templates/kubelet.j2 @@ -14,4 +14,8 @@ KUBELET_HOSTNAME="--hostname_override={{ inventory_hostname }}" KUBELET_API_SERVER="--api_servers=https://{{ groups['masters'][0]}}:443" # Add your own! +{% if dns_setup %} +KUBELET_ARGS="--cluster_dns={{ dns_server }} --cluster_domain={{ dns_domain }} --kubeconfig={{ kube_config_dir}}/kubelet.kubeconfig" +{% else %} KUBELET_ARGS="--kubeconfig={{ kube_config_dir}}/kubelet.kubeconfig" +{% endif %}