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.

85 lines
2.9 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. tags:
  11. - facts
  12. - name: Check if kubelet.conf exists
  13. stat:
  14. path: "{{ kube_config_dir }}/kubelet.conf"
  15. register: kubelet_conf
  16. - name: Calculate kubeadm CA cert hash
  17. 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/^.* //'
  18. register: kubeadm_ca_hash
  19. delegate_to: "{{ groups['kube-master'][0] }}"
  20. run_once: true
  21. - name: Create kubeadm token for joining nodes with 24h expiration (default)
  22. command: "{{ bin_dir }}/kubeadm token create"
  23. run_once: true
  24. register: temp_token
  25. delegate_to: "{{ groups['kube-master'][0] }}"
  26. - name: Create kubeadm client config
  27. template:
  28. src: kubeadm-client.conf.j2
  29. dest: "{{ kube_config_dir }}/kubeadm-client.conf"
  30. backup: yes
  31. when: not is_kube_master
  32. vars:
  33. kubeadm_token: "{{ temp_token.stdout }}"
  34. register: kubeadm_client_conf
  35. - name: Join to cluster if needed
  36. command: >-
  37. {{ bin_dir }}/kubeadm join
  38. --config {{ kube_config_dir}}/kubeadm-client.conf
  39. --ignore-preflight-errors=all
  40. register: kubeadm_join
  41. when: not is_kube_master and (kubeadm_client_conf.changed or not kubelet_conf.stat.exists)
  42. - name: Wait for kubelet bootstrap to create config
  43. wait_for:
  44. path: "{{ kube_config_dir }}/kubelet.conf"
  45. delay: 1
  46. timeout: 60
  47. - name: Update server field in kubelet kubeconfig
  48. lineinfile:
  49. dest: "{{ kube_config_dir }}/kubelet.conf"
  50. regexp: 'server:'
  51. line: ' server: {{ kube_apiserver_endpoint }}'
  52. backup: yes
  53. when: not is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint
  54. notify: restart kubelet
  55. - name: Update server field in kube-proxy kubeconfig
  56. shell: >-
  57. {{ bin_dir }}/kubectl get configmap kube-proxy -n kube-system -o yaml
  58. | sed 's#server:.*#server:\ {{ kube_apiserver_endpoint }}#g'
  59. | kubectl replace -f -
  60. delegate_to: "{{groups['kube-master']|first}}"
  61. run_once: true
  62. when: is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint
  63. - name: Restart all kube-proxy pods to ensure that they load the new configmap
  64. shell: "{{ bin_dir }}/kubectl delete pod -n kube-system -l k8s-app=kube-proxy"
  65. delegate_to: "{{groups['kube-master']|first}}"
  66. run_once: true
  67. when: is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint
  68. # FIXME(mattymo): Reconcile kubelet kubeconfig filename for both deploy modes
  69. - name: Symlink kubelet kubeconfig for calico/canal
  70. file:
  71. src: "{{ kube_config_dir }}//kubelet.conf"
  72. dest: "{{ kube_config_dir }}/node-kubeconfig.yaml"
  73. state: link
  74. force: yes
  75. when: kube_network_plugin in ['calico','canal']