2017-09-14 02:00:51 +08:00
|
|
|
---
|
|
|
|
- name: Set kubeadm_discovery_address
|
|
|
|
set_fact:
|
|
|
|
kubeadm_discovery_address: >-
|
|
|
|
{%- if "127.0.0.1" or "localhost" in kube_apiserver_endpoint -%}
|
|
|
|
{{ first_kube_master }}:{{ kube_apiserver_port }}
|
|
|
|
{%- else -%}
|
|
|
|
{{ kube_apiserver_endpoint }}
|
|
|
|
{%- endif %}
|
2017-10-05 15:43:04 +08:00
|
|
|
tags:
|
|
|
|
- facts
|
2017-09-14 02:00:51 +08:00
|
|
|
|
2017-09-16 05:28:15 +08:00
|
|
|
- name: Check if kubelet.conf exists
|
|
|
|
stat:
|
|
|
|
path: "{{ kube_config_dir }}/kubelet.conf"
|
|
|
|
register: kubelet_conf
|
|
|
|
|
2017-12-25 16:57:45 +08:00
|
|
|
- name: Calculate kubeadm CA cert hash
|
|
|
|
shell: openssl x509 -pubkey -in {{ kube_config_dir }}/ssl/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
|
|
|
|
register: kubeadm_ca_hash
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
|
|
|
run_once: true
|
|
|
|
|
2018-02-06 07:14:50 +08: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] }}"
|
|
|
|
|
2017-09-14 02:00:51 +08:00
|
|
|
- name: Create kubeadm client config
|
|
|
|
template:
|
|
|
|
src: kubeadm-client.conf.j2
|
|
|
|
dest: "{{ kube_config_dir }}/kubeadm-client.conf"
|
|
|
|
backup: yes
|
|
|
|
when: not is_kube_master
|
2018-02-06 22:43:05 +08:00
|
|
|
vars:
|
|
|
|
kubeadm_token: "{{ temp_token.stdout }}"
|
2017-09-14 02:00:51 +08:00
|
|
|
register: kubeadm_client_conf
|
|
|
|
|
|
|
|
- name: Join to cluster if needed
|
2017-12-25 16:57:45 +08:00
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/kubeadm join
|
|
|
|
--config {{ kube_config_dir}}/kubeadm-client.conf
|
|
|
|
--ignore-preflight-errors=all
|
2017-09-14 02:00:51 +08:00
|
|
|
register: kubeadm_join
|
2017-09-16 05:28:15 +08:00
|
|
|
when: not is_kube_master and (kubeadm_client_conf.changed or not kubelet_conf.stat.exists)
|
|
|
|
|
|
|
|
- name: Wait for kubelet bootstrap to create config
|
|
|
|
wait_for:
|
|
|
|
path: "{{ kube_config_dir }}/kubelet.conf"
|
|
|
|
delay: 1
|
|
|
|
timeout: 60
|
2017-09-14 02:00:51 +08:00
|
|
|
|
|
|
|
- name: Update server field in kubelet kubeconfig
|
2018-06-07 17:46:15 +08:00
|
|
|
lineinfile:
|
|
|
|
dest: "{{ kube_config_dir }}/kubelet.conf"
|
|
|
|
regexp: 'server:'
|
|
|
|
line: ' server: {{ kube_apiserver_endpoint }}'
|
2017-09-14 02:00:51 +08:00
|
|
|
backup: yes
|
|
|
|
when: not is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint
|
2017-10-24 23:08:48 +08:00
|
|
|
notify: restart kubelet
|
2017-09-14 02:00:51 +08:00
|
|
|
|
2018-06-12 12:50:52 +08:00
|
|
|
- name: Update server field in kube-proxy kubeconfig
|
|
|
|
shell: >-
|
|
|
|
{{ bin_dir }}/kubectl get configmap kube-proxy -n kube-system -o yaml
|
|
|
|
| sed 's#server:.*#server:\ {{ kube_apiserver_endpoint }}#g'
|
2018-07-13 23:32:08 +08:00
|
|
|
| {{ bin_dir }}/kubectl replace -f -
|
2018-06-12 12:50:52 +08:00
|
|
|
delegate_to: "{{groups['kube-master']|first}}"
|
|
|
|
run_once: true
|
|
|
|
when: is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint
|
|
|
|
|
|
|
|
- name: Restart all kube-proxy pods to ensure that they load the new configmap
|
|
|
|
shell: "{{ bin_dir }}/kubectl delete pod -n kube-system -l k8s-app=kube-proxy"
|
|
|
|
delegate_to: "{{groups['kube-master']|first}}"
|
|
|
|
run_once: true
|
|
|
|
when: is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint
|
|
|
|
|
2017-09-14 02:00:51 +08:00
|
|
|
# FIXME(mattymo): Reconcile kubelet kubeconfig filename for both deploy modes
|
|
|
|
- name: Symlink kubelet kubeconfig for calico/canal
|
|
|
|
file:
|
2018-07-20 15:34:33 +08:00
|
|
|
src: "{{ kube_config_dir }}/kubelet.conf"
|
2017-09-14 02:00:51 +08:00
|
|
|
dest: "{{ kube_config_dir }}/node-kubeconfig.yaml"
|
|
|
|
state: link
|
|
|
|
force: yes
|
|
|
|
when: kube_network_plugin in ['calico','canal']
|