deploy_k8s_services.yml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. # Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - name: Include common variables
  16. include_vars: ../../slurm_exporter/vars/main.yml
  17. - name: Include k8s_nfs_server_setup variables
  18. include_vars: ../../k8s_nfs_server_setup/vars/main.yml
  19. - name: Include powervault_me4_nfs variables
  20. include_vars: ../../powervault_me4_nfs/vars/main.yml
  21. - name: Wait for CoreDNS to restart
  22. command: kubectl rollout status deployment/coredns -n kube-system --timeout=5m
  23. changed_when: false
  24. failed_when: false
  25. tags: init
  26. - name: Get K8s pods
  27. command: kubectl get pods --all-namespaces
  28. changed_when: false
  29. register: k8s_pods
  30. tags: init
  31. - name: Deploy MetalLB
  32. command: "kubectl apply -f '{{ metallb_yaml_url }}'"
  33. changed_when: true
  34. when: "'metallb' not in k8s_pods.stdout"
  35. tags: init
  36. - name: Create MetalLB Setup Config Files
  37. copy:
  38. src: metal-config.yaml
  39. dest: "{{ metallb_config_file_dest }}"
  40. owner: root
  41. group: root
  42. mode: "{{ metallb_config_file_mode }}"
  43. tags: init
  44. - name: Create MetalLB Setup Deployment Files
  45. copy:
  46. src: metallb.yaml
  47. dest: "{{ metallb_deployment_file_dest }}"
  48. owner: root
  49. group: root
  50. mode: "{{ metallb_deployment_file_mode }}"
  51. tags: init
  52. - name: Deploy MetalLB
  53. command: "kubectl apply -f '{{ metallb_deployment_file_dest }}'"
  54. changed_when: true
  55. when: "'metallb' not in k8s_pods.stdout"
  56. tags: init
  57. - name: Create default setup for MetalLB
  58. command: "kubectl apply -f '{{ metallb_config_file_dest }}'"
  59. changed_when: true
  60. when: "'metallb' not in k8s_pods.stdout"
  61. tags: init
  62. - name: Start k8s dashboard
  63. command: "kubectl create -f '{{ k8s_dashboard_yaml_url }}'"
  64. changed_when: true
  65. when: "'kubernetes-dashboard' not in k8s_pods.stdout"
  66. tags: init
  67. - name: Copy k8s_dashboard_admin.yml file
  68. copy:
  69. src: k8s_dashboard_admin.yaml
  70. dest: "{{ k8s_dashboard_admin_file_dest }}"
  71. owner: root
  72. group: root
  73. mode: "{{ k8s_dashboard_admin_file_mode }}"
  74. - name: Create admin user for K8s dashboard
  75. command: "kubectl apply -f {{ k8s_dashboard_admin_file_dest }}"
  76. changed_when: true
  77. - name: Helm - add stable repo
  78. command: "helm repo add stable '{{ helm_stable_repo_url }}'"
  79. changed_when: true
  80. tags: init
  81. - name: Helm - add Nvidia k8s-device-plugin (nvdp) repo
  82. command: "helm repo add nvdp '{{ nvidia_k8s_device_plugin_repo_url }}'"
  83. changed_when: true
  84. tags: init
  85. - name: Helm - add Nvidia GPU discovery (nvgfd) repo
  86. command: "helm repo add nvgfd '{{ nvidia_gpu_discovery_repo_url }}'"
  87. changed_when: true
  88. tags: init
  89. - name: Helm - update repo
  90. command: helm repo update
  91. changed_when: true
  92. tags: init
  93. - name: Start NFS Client Provisioner
  94. command: "helm install stable/nfs-client-provisioner --set nfs.server='{{ nfs_server }}' --set nfs.path='{{ nfs_path }}' --generate-name"
  95. changed_when: true
  96. when: "'nfs-client-provisioner' not in k8s_pods.stdout"
  97. tags: init
  98. - name: Set NFS-Client Provisioner as DEFAULT StorageClass
  99. shell: >
  100. kubectl patch storageclasses.storage.k8s.io nfs-client \
  101. -p '{ "metadata": { "annotations":{ "storageclass.kubernetes.io/is-default-class":"true" }}}'
  102. changed_when: true
  103. tags: init
  104. - name: Check if prometheus is installed on the host
  105. stat:
  106. path: "{{ prometheus_path_on_host }}"
  107. register: prometheus_status
  108. changed_when: False
  109. ignore_errors: yes
  110. tags: init
  111. - name: Delete prometheus installed on host if it exists
  112. file:
  113. path: "{{ prometheus_path_on_host }}"
  114. state: absent
  115. when: prometheus_status.stat.exists
  116. tags: init
  117. - name: Copy the slurm exporter config file
  118. copy:
  119. src: "{{ slurm_exporter_config_file }}"
  120. dest: "{{ slurm_exporter_config_file_path }}"
  121. owner: root
  122. group: root
  123. mode: "{{ slurm_exporter_file_mode }}"
  124. tags: init
  125. - name: Fetch the public IP of the host
  126. shell: >
  127. set -o pipefail && \
  128. ip route get 8.8.8.8 | awk '{print $7}'
  129. register: public_ip
  130. changed_when: False
  131. tags: init
  132. - name: Add the host IP to config file
  133. replace:
  134. path: "{{ slurm_exporter_config_file_path }}{{ slurm_exporter_config_file }}"
  135. regexp: "localhost:8080"
  136. replace: "{{ public_ip.stdout }}:{{ slurm_exporter_port }}"
  137. tags: init
  138. - name: Prometheus deployment
  139. command: >
  140. helm install stable/prometheus \
  141. --set-file extraScrapeConfigs="{{ slurm_exporter_config_file_path }}{{ slurm_exporter_config_file }}" \
  142. --set alertmanager.persistentVolume.storageClass=nfs-client,server.persistentVolume.storageClass=nfs-client,server.service.type=LoadBalancer \
  143. --generate-name
  144. changed_when: true
  145. when: "'prometheus' not in k8s_pods.stdout"
  146. tags: init
  147. - name: Install MPI Operator
  148. command: "kubectl create -f '{{ mpi_operator_yaml_url }}'"
  149. changed_when: true
  150. when: "'mpi-operator' not in k8s_pods.stdout"
  151. tags: init
  152. - name: Install nvidia-device-plugin
  153. command: "helm install --version='{{ nvidia_device_plugin_version }}' --generate-name --set migStrategy='{{ mig_strategy }}' nvdp/nvidia-device-plugin"
  154. changed_when: true
  155. when: "'nvidia-device-plugin' not in k8s_pods.stdout"
  156. tags: init
  157. - name: Install GPU Feature Discovery
  158. command: "helm install --version='{{ gpu_feature_discovery_version }}' --generate-name --set migStrategy='{{ mig_strategy }}' nvgfd/gpu-feature-discovery"
  159. changed_when: true
  160. when: "'node-feature-discovery' not in k8s_pods.stdout"
  161. tags: init
  162. - name: Deploy Xilinx Device plugin
  163. command: "kubectl create -f '{{ fpga_device_plugin_yaml_url }}'"
  164. changed_when: true
  165. register: fpga_enable
  166. when: "'fpga-device-plugin' not in k8s_pods.stdout"
  167. tags: init
  168. - name: Deploy ROCm Device plugin
  169. command: "kubectl create -f '{{ rocm_device_plugin_yaml_url }}'"
  170. changed_when: true
  171. register: amd_gpu_enable
  172. when: "'amdgpu-device-plugin' not in k8s_pods.stdout"
  173. tags: init
  174. - name: Deploy Volcano Scheduling
  175. command: "kubectl apply -f '{{ volcano_scheduling_yaml_url }}'"
  176. changed_when: true
  177. when: "'volcano-system' not in k8s_pods.stdout"
  178. tags: init
  179. - name: Install Spark Operator
  180. command: "helm repo add spark-operator '{{ spark_operator_repo }}'"
  181. changed_when: true
  182. tags: init
  183. - name: Install Spark Operator Namespace
  184. command: helm install my-release spark-operator/spark-operator --set image.tag={{ operator_image_tag }} --namespace spark-operator --create-namespace
  185. changed_when: true
  186. when: "'spark-operator' not in k8s_pods.stdout"
  187. tags: init