k8s.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. - name: Get join token
  2. shell: kubeadm token create --description "ocadm-playbook-node-joining-token" --ttl 15m --print-join-command | awk '{print $5}{print $7}'
  3. register: K8S_JOIN_TOKEN
  4. delegate_to: "{{ k8s_controlplane_host }}"
  5. run_once: yes
  6. environment:
  7. http_proxy: ''
  8. https_proxy: ''
  9. when:
  10. k8s_join_token is not defined or k8s_join_token|length == 0
  11. changed_when: false
  12. - name: Check node is join
  13. shell: test -f /etc/kubernetes/kubelet.conf
  14. register: kubelet_result
  15. ignore_errors: yes
  16. changed_when: false
  17. failed_when: false
  18. - block:
  19. - name: fetch join token
  20. set_fact:
  21. k8s_join_token: "{{ K8S_JOIN_TOKEN.stdout_lines[0] }}"
  22. when:
  23. k8s_join_token is not defined or k8s_join_token|length == 0
  24. - name: construct controlplane endpoint
  25. set_fact:
  26. controlplane_endpoint: "{{k8s_controlplane_host}}:{{ k8s_controlplane_port | default(6443) }}"
  27. - name: construct join args
  28. set_fact:
  29. join_args: "join {{ controlplane_endpoint }} --token {{ k8s_join_token }} --discovery-token-unsafe-skip-ca-verification"
  30. - name: join node as onecloud controller
  31. set_fact:
  32. join_args: "{{ join_args }} --as-onecloud-controller"
  33. when:
  34. - k8s_node_as_oc_controller|default(false)|bool == true
  35. - name: join node as onecloud host agent
  36. set_fact:
  37. join_args: "{{ join_args }} --enable-host-agent"
  38. - name: join node for node-ip
  39. set_fact:
  40. join_args: "{{ join_args }} --node-ip {{ node_ip }}"
  41. when:
  42. node_ip is defined
  43. # define var host_networks if not set.
  44. - name: Set node_interface_name
  45. include_role:
  46. name: utils/set-hostnetworks
  47. when: host_networks is undefined or host_networks == ''
  48. - name: Set host_networks_options
  49. set_fact:
  50. host_networks_options: "{{ host_networks | join(' --host-networks ') }}"
  51. when:
  52. host_networks is defined
  53. - name: construct host network args
  54. set_fact:
  55. join_args: "{{ join_args }} --host-networks {{ host_networks_options }} "
  56. when:
  57. host_networks is defined
  58. - name: construct hugepage args
  59. set_fact:
  60. join_args: "{{ join_args }} --enable-hugepage "
  61. when:
  62. - enable_hugepage is defined
  63. - onecloud_version is defined
  64. - onecloud_version is version('v3.10', '>=')
  65. - name: Wait for port {{ k8s_controlplane_host }}:{{ k8s_controlplane_port | default(6443)}} to be ready
  66. wait_for:
  67. host: "{{ k8s_controlplane_host }}"
  68. port: "{{ k8s_controlplane_port | default(6443)}}"
  69. delay: 5
  70. timeout: 60
  71. become: yes
  72. retries: 3
  73. run_once: yes
  74. - name: "Use 'ocadm {{ join_args }}'"
  75. command: "/opt/yunion/bin/ocadm {{ join_args }}"
  76. environment:
  77. http_proxy: ''
  78. https_proxy: ''
  79. when:
  80. kubelet_result.rc != 0
  81. - name: Include utils/k8s/kubelet/extra-args tasks
  82. include_role:
  83. name: utils/k8s/kubelet/extra-args