You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

  1. ---
  2. - name: Set kubeadm_discovery_address
  3. set_fact:
  4. kubeadm_discovery_address: >-
  5. {%- if "127.0.0.1" or "localhost" in kube_apiserver_endpoint -%}
  6. {{ first_kube_master }}:{{ kube_apiserver_port }}
  7. {%- else -%}
  8. {{ kube_apiserver_endpoint }}
  9. {%- endif %}
  10. when: not is_kube_master
  11. tags:
  12. - facts
  13. - name: Check if kubelet.conf exists
  14. stat:
  15. path: "{{ kube_config_dir }}/kubelet.conf"
  16. register: kubelet_conf
  17. - name: Calculate kubeadm CA cert hash
  18. 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/^.* //'
  19. register: kubeadm_ca_hash
  20. delegate_to: "{{ groups['kube-master'][0] }}"
  21. run_once: true
  22. - name: Create kubeadm client config
  23. template:
  24. src: kubeadm-client.conf.j2
  25. dest: "{{ kube_config_dir }}/kubeadm-client.conf"
  26. backup: yes
  27. when: not is_kube_master
  28. register: kubeadm_client_conf
  29. - name: Join to cluster if needed
  30. command: >-
  31. {{ bin_dir }}/kubeadm join
  32. --config {{ kube_config_dir}}/kubeadm-client.conf
  33. --ignore-preflight-errors=all
  34. register: kubeadm_join
  35. when: not is_kube_master and (kubeadm_client_conf.changed or not kubelet_conf.stat.exists)
  36. - name: Wait for kubelet bootstrap to create config
  37. wait_for:
  38. path: "{{ kube_config_dir }}/kubelet.conf"
  39. delay: 1
  40. timeout: 60
  41. - name: Update server field in kubelet kubeconfig
  42. replace:
  43. path: "{{ kube_config_dir }}/kubelet.conf"
  44. regexp: '(\s+)https://{{ first_kube_master }}:{{ kube_apiserver_port }}(\s+.*)?$'
  45. replace: '\1{{ kube_apiserver_endpoint }}\2'
  46. backup: yes
  47. when: not is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint
  48. notify: restart kubelet
  49. # FIXME(mattymo): Reconcile kubelet kubeconfig filename for both deploy modes
  50. - name: Symlink kubelet kubeconfig for calico/canal
  51. file:
  52. src: "{{ kube_config_dir }}//kubelet.conf"
  53. dest: "{{ kube_config_dir }}/node-kubeconfig.yaml"
  54. state: link
  55. force: yes
  56. when: kube_network_plugin in ['calico','canal']