summaryrefslogtreecommitdiff
path: root/roles/kubernetes/kubeadm/master/tasks/secondary-masters.yml
blob: cb135adc4f7cdbb78350bc6d65acb0d335f55522 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
- name: fetch secrets needed for secondary master
  run_once: true
  delegate_to: "{{ groups['_kubernetes_primary_master_'] | first }}"
  block:

  - name: fetch list of current nodes
    command: kubectl --kubeconfig /etc/kubernetes/admin.conf get nodes -o name
    changed_when: False
    check_mode: no
    register: kubectl_node_list

  - name: save list of current nodes
    set_fact:
      kubernetes_current_nodes: "{{ kubectl_node_list.stdout_lines | map('replace', 'node/', '') | list }}"

  - name: upload certs
    when: "groups['_kubernetes_masters_'] | difference(kubernetes_current_nodes) | length > 0"
    command: kubeadm init phase upload-certs --upload-certs
    check_mode: no
    register: kubeadm_upload_certs


- name: extracting encryption key for certs
  set_fact:
    kubeadm_upload_certs_key: "{% if kubeadm_upload_certs.stdout is defined %}{{ kubeadm_upload_certs.stdout_lines | last }}{% endif %}"

- name: join kubernetes secondary master node and store log
  block:
  - name: join kubernetes secondary master node
    command: "kubeadm join 127.0.0.1:6443 --node-name {{ inventory_hostname }} --apiserver-bind-port 6442{% if kubernetes_overlay_node_ip is defined %} --apiserver-advertise-address {{ kubernetes_overlay_node_ip }}{% endif %}{% if kubernetes_cri_socket %} --cri-socket {{ kubernetes_cri_socket }}{% endif %} --token '{{ kube_bootstrap_token }}' --discovery-token-ca-cert-hash '{{ kube_bootstrap_ca_cert_hash }}' --control-plane --certificate-key {{ kubeadm_upload_certs_key }}"
    args:
      creates: /etc/kubernetes/kubelet.conf
    register: kubeadm_join

  always:
  - name: dump output of kubeadm join to log file
    when: kubeadm_join is changed
    # This is not a handler by design to make sure this action runs at this point of the play.
    copy: # noqa 503
      content: "{{ kubeadm_join.stdout }}\n"
      dest: /etc/kubernetes/kubeadm-join.log

  # TODO: acutally check if node has registered
- name: give the new master(s) a moment to register
  when: kubeadm_join is changed
  pause: # noqa 503
    seconds: 5