2017-09-14 02:00:51 +08:00
|
|
|
---
|
|
|
|
- name: Set kubeadm_discovery_address
|
|
|
|
set_fact:
|
|
|
|
kubeadm_discovery_address: >-
|
2018-08-07 18:25:31 +08:00
|
|
|
{%- if "127.0.0.1" in kube_apiserver_endpoint or "localhost" in kube_apiserver_endpoint -%}
|
2017-09-14 02:00:51 +08:00
|
|
|
{{ first_kube_master }}:{{ kube_apiserver_port }}
|
|
|
|
{%- else -%}
|
2019-06-28 15:37:37 +08:00
|
|
|
{{ kube_apiserver_endpoint | replace("https://", "") }}
|
2017-09-14 02:00:51 +08:00
|
|
|
{%- endif %}
|
2017-10-05 15:43:04 +08:00
|
|
|
tags:
|
|
|
|
- facts
|
2017-09-14 02:00:51 +08:00
|
|
|
|
2019-06-21 02:12: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
|
2018-12-07 15:11:53 +08: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 16:57:45 +08:00
|
|
|
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"
|
|
|
|
register: temp_token
|
|
|
|
delegate_to: "{{ groups['kube-master'][0] }}"
|
2019-04-19 21:01:54 +08:00
|
|
|
when: kubeadm_token is not defined
|
|
|
|
|
|
|
|
- name: Set kubeadm_token to generated token
|
|
|
|
set_fact:
|
|
|
|
kubeadm_token: "{{ temp_token.stdout }}"
|
|
|
|
when: kubeadm_token is not defined
|
|
|
|
|
2018-02-06 07:14:50 +08:00
|
|
|
|
2018-08-14 20:13:44 +08:00
|
|
|
- name: gets the kubeadm version
|
|
|
|
command: "{{ bin_dir }}/kubeadm version -o short"
|
|
|
|
register: kubeadm_output
|
|
|
|
|
2018-12-07 04:11:48 +08:00
|
|
|
- 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 20:13:44 +08:00
|
|
|
|
2017-09-14 02:00:51 +08:00
|
|
|
- name: Create kubeadm client config
|
|
|
|
template:
|
2018-08-14 20:13:44 +08:00
|
|
|
src: "kubeadm-client.conf.{{ kubeadmConfig_api_version }}.j2"
|
2018-12-19 21:16:14 +08:00
|
|
|
dest: "{{ kube_config_dir }}/kubeadm-client.conf"
|
2017-09-14 02:00:51 +08:00
|
|
|
backup: yes
|
|
|
|
when: not is_kube_master
|
|
|
|
|
|
|
|
- name: Join to cluster if needed
|
2018-09-19 07:48:45 +08:00
|
|
|
environment:
|
2019-05-27 16:49:51 +08:00
|
|
|
PATH: "{{ bin_dir }}:{{ ansible_env.PATH }}:/sbin" # Make sure we can workaround RH / CentOS conservative path management
|
2019-02-13 05:42:56 +08:00
|
|
|
when: not is_kube_master and (not kubelet_conf.stat.exists)
|
|
|
|
block:
|
|
|
|
|
|
|
|
- name: Join to cluster
|
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/kubeadm join
|
2019-05-03 05:24:21 +08:00
|
|
|
--config {{ kube_config_dir }}/kubeadm-client.conf
|
2019-02-20 14:13:59 +08:00
|
|
|
--ignore-preflight-errors=DirAvailable--etc-kubernetes-manifests
|
2019-02-13 05:42:56 +08:00
|
|
|
register: kubeadm_join
|
2019-04-20 22:05:40 +08:00
|
|
|
async: 120
|
2019-02-13 05:42:56 +08:00
|
|
|
poll: 15
|
|
|
|
|
|
|
|
rescue:
|
|
|
|
|
|
|
|
- name: Join to cluster with ignores
|
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/kubeadm join
|
2019-05-03 05:24:21 +08:00
|
|
|
--config {{ kube_config_dir }}/kubeadm-client.conf
|
2019-02-13 05:42:56 +08:00
|
|
|
--ignore-preflight-errors=all
|
|
|
|
register: kubeadm_join
|
2019-05-28 16:51:53 +08:00
|
|
|
async: 180
|
2019-02-13 05:42:56 +08:00
|
|
|
poll: 15
|
|
|
|
|
|
|
|
always:
|
|
|
|
|
|
|
|
- name: Display kubeadm join stderr if any
|
|
|
|
when: kubeadm_join is failed
|
|
|
|
debug:
|
2019-05-04 03:21:42 +08:00
|
|
|
msg: |
|
2019-02-13 05:42:56 +08:00
|
|
|
Joined with warnings
|
|
|
|
{{ kubeadm_join.stderr_lines }}
|
2017-09-16 05:28:15 +08:00
|
|
|
|
|
|
|
- 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
|
2018-08-18 22:05:35 +08:00
|
|
|
when:
|
|
|
|
- kubeadm_config_api_fqdn is not defined
|
|
|
|
- not is_kube_master
|
2019-06-28 15:37:37 +08:00
|
|
|
- kubeadm_discovery_address != kube_apiserver_endpoint | replace("https://", "")
|
2017-10-24 23:08:48 +08:00
|
|
|
notify: restart kubelet
|
2017-09-14 02:00:51 +08:00
|
|
|
|
2019-01-11 12:40:25 +08:00
|
|
|
- name: Update server field in kube-proxy kubeconfig
|
|
|
|
shell: >-
|
|
|
|
{{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf get configmap kube-proxy -n kube-system -o yaml
|
|
|
|
| sed 's#server:.*#server:\ {{ kube_apiserver_endpoint }}#g'
|
|
|
|
| {{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf replace -f -
|
|
|
|
run_once: true
|
|
|
|
when:
|
2019-04-19 21:01:54 +08:00
|
|
|
- inventory_hostname == groups['kube-master']|first
|
2019-01-11 12:40:25 +08:00
|
|
|
- kubeadm_config_api_fqdn is not defined
|
2019-06-28 15:37:37 +08:00
|
|
|
- kubeadm_discovery_address != kube_apiserver_endpoint | replace("https://", "")
|
2019-01-11 12:40:25 +08:00
|
|
|
- not kube_proxy_remove
|
|
|
|
tags:
|
|
|
|
- kube-proxy
|
|
|
|
|
|
|
|
- name: Restart all kube-proxy pods to ensure that they load the new configmap
|
2019-03-14 22:45:46 +08:00
|
|
|
shell: "{{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf delete pod -n kube-system -l k8s-app=kube-proxy --force --grace-period=0"
|
2019-01-11 12:40:25 +08:00
|
|
|
run_once: true
|
|
|
|
when:
|
2019-04-19 21:01:54 +08:00
|
|
|
- inventory_hostname == groups['kube-master']|first
|
2019-01-11 12:40:25 +08:00
|
|
|
- kubeadm_config_api_fqdn is not defined
|
2019-06-28 15:37:37 +08:00
|
|
|
- kubeadm_discovery_address != kube_apiserver_endpoint | replace("https://", "")
|
2019-01-11 12:40:25 +08:00
|
|
|
- not kube_proxy_remove
|
|
|
|
tags:
|
|
|
|
- kube-proxy
|
|
|
|
|
2018-08-23 22:17:18 +08: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-29 03:03:49 +08:00
|
|
|
when:
|
|
|
|
- kube_network_plugin in ['calico','canal']
|
|
|
|
- calico_version is version('v3.3.0', '<')
|
2018-08-23 22:17:18 +08:00
|
|
|
|
2018-10-16 22:15:05 +08: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 18:33:38 +08:00
|
|
|
shell: "{{ bin_dir }}/kubectl --kubeconfig /etc/kubernetes/admin.conf delete daemonset -n kube-system kube-proxy"
|
2018-10-16 22:15:05 +08:00
|
|
|
run_once: true
|
|
|
|
when:
|
2019-04-19 21:01:54 +08:00
|
|
|
- inventory_hostname == groups['kube-master']|first
|
2018-10-16 22:15:05 +08:00
|
|
|
- kube_proxy_remove
|
2019-06-28 15:37:37 +08:00
|
|
|
- kubeadm_discovery_address != kube_apiserver_endpoint | replace("https://", "")
|
2018-10-16 22:15:05 +08:00
|
|
|
tags:
|
|
|
|
- kube-proxy
|
2019-06-21 02:12:51 +08:00
|
|
|
|
|
|
|
- name: Extract etcd certs from control plane if using etcd kubeadm mode
|
|
|
|
include_tasks: kubeadm_etcd_node.yml
|
|
|
|
when:
|
|
|
|
- etcd_kubeadm_enabled
|
|
|
|
- kubeadm_control_plane
|
|
|
|
- inventory_hostname not in groups['kube-master']
|
|
|
|
- kube_network_plugin in ["calico", "flannel", "canal", "cilium"]
|
|
|
|
- kube_network_plugin != "calico" or calico_datastore == "etcd"
|