k8s.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. - name: Include utils/controlplane tasks
  2. include_role:
  3. name: utils/controlplane
  4. - name: Check node is join
  5. shell: test -f /etc/kubernetes/kubelet.conf
  6. register: kubelet_result
  7. ignore_errors: yes
  8. changed_when: false
  9. failed_when: false
  10. - name: Get join token
  11. shell: kubeadm token create --description "ocadm-playbook-node-joining-token" --ttl 15m --print-join-command | awk '{print $5}{print $7}'
  12. register: K8S_JOIN_TOKEN
  13. delegate_to: "{{ k8s_controlplane_host }}"
  14. run_once: yes
  15. environment:
  16. http_proxy: ''
  17. https_proxy: ''
  18. when:
  19. k8s_join_token is not defined or k8s_join_token|length == 0
  20. changed_when: false
  21. - name: Get certificate key
  22. shell: /opt/yunion/bin/ocadm init phase upload-certs | grep -v upload-certs
  23. register: K8S_CERT_KEY
  24. delegate_to: "{{ k8s_controlplane_host }}"
  25. run_once: yes
  26. environment:
  27. http_proxy: ''
  28. https_proxy: ''
  29. when:
  30. k8s_join_certificate_key is not defined or k8s_join_certificate_key|length == 0
  31. - name: construct k8s_controlplane_host
  32. set_fact:
  33. k8s_controlplane_host: "{{groups['primary_master_node'][0]}}"
  34. when:
  35. k8s_controlplane_host is not defined or k8s_controlplane_host|length == 0
  36. - block:
  37. - name: fetch join token
  38. set_fact:
  39. k8s_join_token: "{{ K8S_JOIN_TOKEN.stdout_lines[0] }}"
  40. when:
  41. k8s_join_token is not defined or k8s_join_token|length == 0
  42. - name: fetch certificate key
  43. set_fact:
  44. k8s_join_certificate_key: "{{ K8S_CERT_KEY.stdout_lines[0] }}"
  45. when:
  46. k8s_join_certificate_key is not defined or k8s_join_certificate_key|length == 0
  47. - name: construct controlplane endpoint
  48. set_fact:
  49. controlplane_endpoint: "{{k8s_controlplane_host}}:{{ k8s_controlplane_port | default(6443) }}"
  50. - name: construct join args
  51. set_fact:
  52. join_args: "join --control-plane {{ controlplane_endpoint }} --token {{ k8s_join_token }} --certificate-key {{ k8s_join_certificate_key }} --discovery-token-unsafe-skip-ca-verification"
  53. - name: join node for apiserver-advertise-address
  54. set_fact:
  55. join_args: "{{ join_args }} --apiserver-advertise-address {{ node_ip }}"
  56. when:
  57. k8s_node_as_oc_controller|default(false)|bool == true
  58. - name: join node for node-ip
  59. set_fact:
  60. join_args: "{{ join_args }} --node-ip {{ node_ip }}"
  61. when:
  62. node_ip is defined
  63. # define var host_networks if not set.
  64. - name: Set node_interface_name
  65. include_role:
  66. name: utils/set-hostnetworks
  67. when: host_networks is undefined or host_networks == ''
  68. - name: Set host_networks_options
  69. set_fact:
  70. host_networks_options: "{{ host_networks | join(' --host-networks ') }}"
  71. when:
  72. host_networks is defined
  73. - name: construct host network args
  74. set_fact:
  75. join_args: "{{ join_args }} --host-networks {{ host_networks_options }} "
  76. when:
  77. host_networks is defined
  78. - name: construct hugepage args
  79. set_fact:
  80. join_args: "{{ join_args }} --enable-hugepage "
  81. when:
  82. - enable_hugepage is defined
  83. - onecloud_version is defined
  84. - onecloud_version is version('v3.10', '>=')
  85. - name: join node as onecloud controller
  86. set_fact:
  87. join_args: "{{ join_args }} --as-onecloud-controller"
  88. when:
  89. - k8s_node_as_oc_controller|default(false)|bool == true
  90. - name: join node as onecloud host agent
  91. set_fact:
  92. join_args: "{{ join_args }} --enable-host-agent"
  93. when:
  94. - join_as_host | default(false)|bool == true
  95. - name: join with high availibility ip option
  96. set_fact:
  97. join_args: "{{ join_args }} --high-availability-vip {{ high_availability_vip }}"
  98. when:
  99. - high_availability_vip is defined
  100. - name: join keepalived version tag
  101. set_fact:
  102. join_args: "{{ join_args }} --keepalived-version-tag {{ keepalived_version_tag }}"
  103. when:
  104. - high_availability_vip is defined
  105. - keepalived_version_tag is defined
  106. - name: disable-resource-management for join
  107. set_fact:
  108. init_cluster_args: "{{ join_args }} --disable-resource-management"
  109. when:
  110. - is_kylin_based is defined
  111. - is_kylin_based |default(false)|bool == true
  112. - name: show ocadm join args
  113. debug:
  114. msg: "/opt/yunion/bin/ocadm {{ join_args }}"
  115. - name: Wait for port {{ k8s_controlplane_host }}:{{ k8s_controlplane_port | default(6443)}} to be ready
  116. wait_for:
  117. host: "{{ k8s_controlplane_host }}"
  118. port: "{{ k8s_controlplane_port | default(6443)}}"
  119. delay: 5
  120. timeout: 60
  121. become: yes
  122. retries: 3
  123. run_once: yes
  124. - name: Use ocadm join master node
  125. command: "/opt/yunion/bin/ocadm {{ join_args }}"
  126. environment:
  127. http_proxy: ''
  128. https_proxy: ''
  129. when:
  130. kubelet_result.rc != 0