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 -%}
|
|
|
|
{{ first_kube_master }}:{{ kube_apiserver_port }}
|
|
|
|
{%- 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:
|
|
|
|
- inventory_hostname == groups['kube-master']|first
|
2019-04-23 21:37:59 +00:00
|
|
|
|
|
|
|
- name: Parse certificate key if not set
|
|
|
|
set_fact:
|
|
|
|
kubeadm_certificate_key: "{{ hostvars[groups['kube-master'][0]]['kubeadm_upload_cert'].stdout_lines[-1] | trim }}"
|
2019-07-15 07:45:06 +00:00
|
|
|
run_once: yes
|
|
|
|
when:
|
|
|
|
- hostvars[groups['kube-master'][0]]['kubeadm_upload_cert'] is defined
|
|
|
|
- hostvars[groups['kube-master'][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:
|
|
|
|
- inventory_hostname != groups['kube-master']|first
|
|
|
|
- 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 }}"
|
|
|
|
|
2019-04-19 13:01:54 +00:00
|
|
|
- name: Joining control plane node to the cluster.
|
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 }};
|
|
|
|
fi &&
|
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-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:
|
|
|
|
- inventory_hostname != groups['kube-master']|first
|
2019-06-20 18:12:51 +00:00
|
|
|
- kubeadm_already_run is not defined or not kubeadm_already_run.stat.exists
|