2017-09-13 18:00:51 +00:00
|
|
|
---
|
|
|
|
- name: Set kubeadm_discovery_address
|
|
|
|
set_fact:
|
|
|
|
kubeadm_discovery_address: >-
|
2018-08-07 10:25:31 +00:00
|
|
|
{%- if "127.0.0.1" in kube_apiserver_endpoint or "localhost" in kube_apiserver_endpoint -%}
|
2017-09-13 18:00:51 +00:00
|
|
|
{{ first_kube_master }}:{{ kube_apiserver_port }}
|
|
|
|
{%- else -%}
|
|
|
|
{{ kube_apiserver_endpoint }}
|
|
|
|
{%- endif %}
|
2017-10-05 07:43:04 +00:00
|
|
|
tags:
|
|
|
|
- facts
|
2017-09-13 18:00:51 +00:00
|
|
|
|
2017-09-15 21:28:15 +00:00
|
|
|
- name: Check if kubelet.conf exists
|
|
|
|
stat:
|
|
|
|
path: "{{ kube_config_dir }}/kubelet.conf"
|
|
|
|
register: kubelet_conf
|
|
|
|
|
2017-12-25 08:57:45 +00:00
|
|
|
- name: Calculate kubeadm CA cert hash
|
2018-12-07 07:11:53 +00:00
|
|
|
shell: openssl x509 -pubkey -in {{ kube_cert_dir }}/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
|
2017-12-25 08:57:45 +00:00
|
|
|
register: kubeadm_ca_hash
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
|
|
|
run_once: true
|
|
|
|
|
2018-02-05 23:14:50 +00:00
|
|
|
- name: Create kubeadm token for joining nodes with 24h expiration (default)
|
|
|
|
command: "{{ bin_dir }}/kubeadm token create"
|
|
|
|
run_once: true
|
|
|
|
register: temp_token
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
|
|
|
|
2018-08-14 12:13:44 +00:00
|
|
|
- name: gets the kubeadm version
|
|
|
|
command: "{{ bin_dir }}/kubeadm version -o short"
|
|
|
|
register: kubeadm_output
|
|
|
|
|
|
|
|
- name: sets kubeadm api version to v1alpha1
|
|
|
|
set_fact:
|
|
|
|
kubeadmConfig_api_version: v1alpha1
|
2018-10-16 22:33:30 +00:00
|
|
|
when: kubeadm_output.stdout is version('v1.11.0', '<')
|
2018-08-14 12:13:44 +00:00
|
|
|
|
2018-10-04 09:05:55 +00:00
|
|
|
- name: sets kubeadm api version to v1alpha2
|
2018-08-14 12:13:44 +00:00
|
|
|
set_fact:
|
|
|
|
kubeadmConfig_api_version: v1alpha2
|
2018-10-04 09:05:55 +00:00
|
|
|
when:
|
2018-10-16 22:33:30 +00:00
|
|
|
- kubeadm_output.stdout is version('v1.11.0', '>=')
|
|
|
|
- kubeadm_output.stdout is version('v1.12.0', '<')
|
2018-10-04 09:05:55 +00:00
|
|
|
|
|
|
|
- name: sets kubeadm api version to v1alpha3
|
|
|
|
set_fact:
|
|
|
|
kubeadmConfig_api_version: v1alpha3
|
2018-12-06 20:11:48 +00:00
|
|
|
when:
|
|
|
|
- kubeadm_output.stdout is version('v1.12.0', '>=')
|
|
|
|
- kubeadm_output.stdout is version('v1.13.0', '<')
|
|
|
|
|
|
|
|
- name: sets kubeadm api version to v1beta1
|
|
|
|
set_fact:
|
|
|
|
kubeadmConfig_api_version: v1beta1
|
|
|
|
when: kubeadm_output.stdout is version('v1.13.0', '>=')
|
2018-08-14 12:13:44 +00:00
|
|
|
|
2017-09-13 18:00:51 +00:00
|
|
|
- name: Create kubeadm client config
|
|
|
|
template:
|
2018-08-14 12:13:44 +00:00
|
|
|
src: "kubeadm-client.conf.{{ kubeadmConfig_api_version }}.j2"
|
2018-12-19 13:16:14 +00:00
|
|
|
dest: "{{ kube_config_dir }}/kubeadm-client.conf"
|
2017-09-13 18:00:51 +00:00
|
|
|
backup: yes
|
|
|
|
when: not is_kube_master
|
2018-02-06 14:43:05 +00:00
|
|
|
vars:
|
|
|
|
kubeadm_token: "{{ temp_token.stdout }}"
|
2017-09-13 18:00:51 +00:00
|
|
|
|
|
|
|
- name: Join to cluster if needed
|
2018-09-18 23:48:45 +00:00
|
|
|
environment:
|
|
|
|
PATH: "{{ bin_dir }}:{{ ansible_env.PATH }}"
|
2019-02-12 21:42:56 +00:00
|
|
|
when: not is_kube_master and (not kubelet_conf.stat.exists)
|
|
|
|
block:
|
|
|
|
|
|
|
|
- name: Join to cluster
|
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/kubeadm join
|
|
|
|
--config {{ kube_config_dir}}/kubeadm-client.conf
|
|
|
|
register: kubeadm_join
|
|
|
|
async: 60
|
|
|
|
poll: 15
|
|
|
|
|
|
|
|
rescue:
|
|
|
|
|
|
|
|
- name: Join to cluster with ignores
|
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/kubeadm join
|
|
|
|
--config {{ kube_config_dir}}/kubeadm-client.conf
|
|
|
|
--ignore-preflight-errors=all
|
|
|
|
register: kubeadm_join
|
|
|
|
async: 60
|
|
|
|
poll: 15
|
|
|
|
|
|
|
|
always:
|
|
|
|
|
|
|
|
- name: Display kubeadm join stderr if any
|
|
|
|
when: kubeadm_join is failed
|
|
|
|
debug:
|
|
|
|
message: |
|
|
|
|
Joined with warnings
|
|
|
|
{{ kubeadm_join.stderr_lines }}
|
2017-09-15 21:28:15 +00:00
|
|
|
|
|
|
|
- name: Wait for kubelet bootstrap to create config
|
|
|
|
wait_for:
|
|
|
|
path: "{{ kube_config_dir }}/kubelet.conf"
|
|
|
|
delay: 1
|
|
|
|
timeout: 60
|
2017-09-13 18:00:51 +00:00
|
|
|
|
|
|
|
- name: Update server field in kubelet kubeconfig
|
2018-06-07 09:46:15 +00:00
|
|
|
lineinfile:
|
|
|
|
dest: "{{ kube_config_dir }}/kubelet.conf"
|
|
|
|
regexp: 'server:'
|
|
|
|
line: ' server: {{ kube_apiserver_endpoint }}'
|
2017-09-13 18:00:51 +00:00
|
|
|
backup: yes
|
2018-08-18 14:05:35 +00:00
|
|
|
when:
|
|
|
|
- kubeadm_config_api_fqdn is not defined
|
|
|
|
- not is_kube_master
|
|
|
|
- kubeadm_discovery_address != kube_apiserver_endpoint
|
2017-10-24 15:08:48 +00:00
|
|
|
notify: restart kubelet
|
2017-09-13 18:00:51 +00:00
|
|
|
|
2018-08-23 14:17:18 +00:00
|
|
|
# FIXME(mattymo): Reconcile kubelet kubeconfig filename for both deploy modes
|
|
|
|
- name: Symlink kubelet kubeconfig for calico/canal
|
|
|
|
file:
|
|
|
|
src: "{{ kube_config_dir }}/kubelet.conf"
|
|
|
|
dest: "{{ kube_config_dir }}/node-kubeconfig.yaml"
|
|
|
|
state: link
|
|
|
|
force: yes
|
2019-01-28 19:03:49 +00:00
|
|
|
when:
|
|
|
|
- kube_network_plugin in ['calico','canal']
|
|
|
|
- calico_version is version('v3.3.0', '<')
|
2018-08-23 14:17:18 +00:00
|
|
|
|
2018-10-16 14:15:05 +00:00
|
|
|
# FIXME(jjo): need to post-remove kube-proxy until https://github.com/kubernetes/kubeadm/issues/776
|
|
|
|
# is fixed
|
|
|
|
- name: Delete kube-proxy daemonset if kube_proxy_remove set, e.g. kube_network_plugin providing proxy services
|
2018-12-06 10:33:38 +00:00
|
|
|
shell: "{{ bin_dir }}/kubectl --kubeconfig /etc/kubernetes/admin.conf delete daemonset -n kube-system kube-proxy"
|
2018-10-16 14:15:05 +00:00
|
|
|
delegate_to: "{{groups['kube-master']|first}}"
|
|
|
|
run_once: true
|
|
|
|
when:
|
|
|
|
- kube_proxy_remove
|
|
|
|
- is_kube_master
|
|
|
|
- kubeadm_discovery_address != kube_apiserver_endpoint
|
|
|
|
tags:
|
|
|
|
- kube-proxy
|