2019-04-19 13:01:54 +00:00
|
|
|
---
|
|
|
|
- name: Set kubeadm_discovery_address
|
|
|
|
set_fact:
|
|
|
|
kubeadm_discovery_address: >-
|
|
|
|
{%- if "127.0.0.1" in kube_apiserver_endpoint or "localhost" in kube_apiserver_endpoint -%}
|
2022-01-10 09:35:19 +00:00
|
|
|
{{ first_kube_control_plane_address }}:{{ kube_apiserver_port }}
|
2019-04-19 13:01:54 +00:00
|
|
|
{%- else -%}
|
2019-05-02 21:24:21 +00:00
|
|
|
{{ kube_apiserver_endpoint | regex_replace('https://', '') }}
|
2019-04-19 13:01:54 +00:00
|
|
|
{%- endif %}
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
|
2019-04-23 21:37:59 +00:00
|
|
|
- name: Upload certificates so they are fresh and not expired
|
|
|
|
command: >-
|
|
|
|
{{ bin_dir }}/kubeadm init phase
|
2019-05-02 21:24:21 +00:00
|
|
|
--config {{ kube_config_dir }}/kubeadm-config.yaml
|
2019-07-02 08:51:08 +00:00
|
|
|
upload-certs
|
|
|
|
--upload-certs
|
2019-04-23 21:37:59 +00:00
|
|
|
register: kubeadm_upload_cert
|
2019-04-27 08:14:20 +00:00
|
|
|
when:
|
2021-12-06 08:16:32 +00:00
|
|
|
- inventory_hostname == first_kube_control_plane
|
2022-04-12 12:47:23 +00:00
|
|
|
- not kube_external_ca_mode
|
2019-04-23 21:37:59 +00:00
|
|
|
|
|
|
|
- name: Parse certificate key if not set
|
|
|
|
set_fact:
|
2021-03-24 00:26:05 +00:00
|
|
|
kubeadm_certificate_key: "{{ hostvars[groups['kube_control_plane'][0]]['kubeadm_upload_cert'].stdout_lines[-1] | trim }}"
|
2019-07-15 07:45:06 +00:00
|
|
|
run_once: yes
|
|
|
|
when:
|
2021-03-24 00:26:05 +00:00
|
|
|
- hostvars[groups['kube_control_plane'][0]]['kubeadm_upload_cert'] is defined
|
|
|
|
- hostvars[groups['kube_control_plane'][0]]['kubeadm_upload_cert'] is not skipped
|
2019-07-11 12:30:54 +00:00
|
|
|
|
|
|
|
- name: Create kubeadm ControlPlane config
|
|
|
|
template:
|
|
|
|
src: "kubeadm-controlplane.{{ kubeadmConfig_api_version }}.yaml.j2"
|
|
|
|
dest: "{{ kube_config_dir }}/kubeadm-controlplane.yaml"
|
2019-11-11 13:41:41 +00:00
|
|
|
mode: 0640
|
2019-07-11 12:30:54 +00:00
|
|
|
backup: yes
|
|
|
|
when:
|
2021-12-06 08:16:32 +00:00
|
|
|
- inventory_hostname != first_kube_control_plane
|
2019-07-11 12:30:54 +00:00
|
|
|
- not kubeadm_already_run.stat.exists
|
|
|
|
|
|
|
|
- name: Wait for k8s apiserver
|
|
|
|
wait_for:
|
|
|
|
host: "{{ kubeadm_discovery_address.split(':')[0] }}"
|
|
|
|
port: "{{ kubeadm_discovery_address.split(':')[1] }}"
|
|
|
|
timeout: 180
|
|
|
|
|
|
|
|
|
2019-06-20 18:12:51 +00:00
|
|
|
- name: check already run
|
|
|
|
debug:
|
|
|
|
msg: "{{ kubeadm_already_run.stat.exists }}"
|
|
|
|
|
2022-04-12 12:47:23 +00:00
|
|
|
- name: Reset cert directory
|
2019-10-08 07:15:12 +00:00
|
|
|
shell: >-
|
|
|
|
if [ -f /etc/kubernetes/manifests/kube-apiserver.yaml ]; then
|
|
|
|
{{ bin_dir }}/kubeadm reset -f --cert-dir {{ kube_cert_dir }};
|
2022-04-12 12:47:23 +00:00
|
|
|
fi
|
|
|
|
environment:
|
|
|
|
PATH: "{{ bin_dir }}:{{ ansible_env.PATH }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname != first_kube_control_plane
|
|
|
|
- kubeadm_already_run is not defined or not kubeadm_already_run.stat.exists
|
|
|
|
- not kube_external_ca_mode
|
|
|
|
|
|
|
|
- name: Joining control plane node to the cluster.
|
|
|
|
command: >-
|
2019-04-19 13:01:54 +00:00
|
|
|
{{ bin_dir }}/kubeadm join
|
2019-05-02 21:24:21 +00:00
|
|
|
--config {{ kube_config_dir }}/kubeadm-controlplane.yaml
|
2019-04-19 13:01:54 +00:00
|
|
|
--ignore-preflight-errors=all
|
2021-10-11 16:36:41 +00:00
|
|
|
--skip-phases={{ kubeadm_join_phases_skip | join(',') }}
|
2021-02-23 17:44:02 +00:00
|
|
|
environment:
|
|
|
|
PATH: "{{ bin_dir }}:{{ ansible_env.PATH }}"
|
2019-04-19 13:01:54 +00:00
|
|
|
register: kubeadm_join_control_plane
|
2019-06-20 18:12:51 +00:00
|
|
|
retries: 3
|
2021-01-16 01:19:43 +00:00
|
|
|
throttle: 1
|
2019-06-20 18:12:51 +00:00
|
|
|
until: kubeadm_join_control_plane is succeeded
|
2019-04-19 13:01:54 +00:00
|
|
|
when:
|
2021-12-06 08:16:32 +00:00
|
|
|
- inventory_hostname != first_kube_control_plane
|
2019-06-20 18:12:51 +00:00
|
|
|
- kubeadm_already_run is not defined or not kubeadm_already_run.stat.exists
|