main.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ---
  2. - name: Turn Swap OFF (if not already disabled)
  3. command: /usr/sbin/swapoff -a
  4. tags: init
  5. - name: Initialize kubeadm
  6. command: /bin/kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.0.0.1
  7. #command: /bin/kubeadm init
  8. register: init_output
  9. tags: init
  10. - name: Setup Directory for Kubernetes environment for root
  11. file: path=/root/.kube state=directory
  12. tags: init
  13. - name: Copy Kubernetes Config for root #do this for other users too?
  14. copy: src=/etc/kubernetes/admin.conf dest=/root/.kube/config owner=root group=root mode=644
  15. tags: init
  16. - name: Cluster token
  17. shell: kubeadm token list | cut -d ' ' -f1 | sed -n '2p'
  18. register: K8S_TOKEN
  19. tags: init
  20. - name: CA Hash
  21. shell: openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
  22. register: K8S_MASTER_CA_HASH
  23. tags: init
  24. - name: Add K8S Master IP, Token, and Hash to dummy host
  25. add_host:
  26. name: "K8S_TOKEN_HOLDER"
  27. token: "{{ K8S_TOKEN.stdout }}"
  28. hash: "{{ K8S_MASTER_CA_HASH.stdout }}"
  29. #ip: "{{ ansible_ib0.ipv4.address }}"
  30. ip: "{{ ansible_p3p1.ipv4.address }}"
  31. tags: init
  32. - name:
  33. debug:
  34. msg: "[Master] K8S_TOKEN_HOLDER K8S token is {{ hostvars['K8S_TOKEN_HOLDER']['token'] }}"
  35. tags: init
  36. - name:
  37. debug:
  38. msg: "[Master] K8S_TOKEN_HOLDER K8S Hash is {{ hostvars['K8S_TOKEN_HOLDER']['hash'] }}"
  39. tags: init
  40. - name:
  41. debug:
  42. msg: "[Master] K8S_MASTER_IP is {{ hostvars['K8S_TOKEN_HOLDER']['ip'] }}"
  43. tags: init
  44. - name: Setup Flannel SDN network
  45. shell: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  46. tags: init
  47. - name: Enabled GPU support in Kubernetes
  48. #script: enable_gpu_k8s.sh
  49. shell: kubectl create -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/1.0.0-beta4/nvidia-device-plugin.yml
  50. #https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v1.11/nvidia-device-plugin.yml
  51. register: gpu_enable
  52. tags: init
  53. - name: Create yaml repo for setup
  54. file:
  55. path: /root/k8s
  56. state: directory
  57. tags: init
  58. #- name: Persistent Volume Setup Files
  59. #copy: src=persistent_volumes.yaml dest=/root/k8s/persistent_volumes.yaml owner=root group=root mode=655
  60. #tags: init
  61. #
  62. #- name: Persistent Volume Setup - Apply
  63. #shell: kubectl apply -f /root/k8s/persistent_volumes.yaml
  64. #tags: init
  65. #
  66. #- name: Copy Service Account (NFS Setup)
  67. #copy: src=nfs-serviceaccount.yaml dest=/root/k8s/nfs-serviceaccount.yaml owner=root group=root mode=655
  68. #tags: init
  69. #
  70. #- name: Copy Cluster Role (NFS Setup)
  71. #copy: src=nfs_clusterrole.yaml dest=/root/k8s/nfs_clusterrole.yaml owner=root group=root mode=655
  72. #tags: init
  73. #
  74. #- name: Copy Cluster Role Binding (NFS Setup)
  75. #copy: src=nfs_clusterrolebinding.yaml dest=/root/k8s/nfs_clusterrolebinding.yaml owner=root group=root mode=655
  76. #tags: init
  77. #
  78. #- name: Copy NFS Storage Deployment (NFS Setup)
  79. #copy: src=nfs-deployment.yaml dest=/root/k8s/nfs-deployment.yaml owner=root group=root mode=655
  80. #tags: init
  81. #
  82. #- name: Copy NFS Storage Class (NFS Setup)
  83. #copy: src=nfs-class.yaml dest=/root/k8s/nfs-class.yaml owner=root group=root mode=655
  84. #tags: init
  85. #
  86. #- name: Deploy NFS (NFS Setup)
  87. #shell: kubectl create -f /root/k8s/nfs-deployment.yaml -f /root/k8s/nfs-class.yaml -f /root/k8s/nfs-serviceaccount.yaml -f /root/k8s/nfs_clusterrole.yaml -f /root/k8s/nfs_clusterrolebinding.yaml
  88. #tags: init
  89. #- name: Patch NFS Setup (NFS Setup)
  90. #shell: kubectl patch deployment nfs-client-provisioner -p '{"spec":{"template":{"spec":{"serviceAccount":"nfs-client-provisioner"}}}}'
  91. #tags: init
  92. #- name: Patch NFS Setup (NFS Setup)
  93. #shell: "kubectl patch storageclass managed-nfs-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'"
  94. #tags: init
  95. - name: Create Service Account (K8S Dashboard) Files
  96. copy: src=create_admin_user.yaml dest=/root/k8s/create_admin_user.yaml owner=root group=root mode=655
  97. tags: init
  98. - name: Create Service Account (K8S Dashboard) - Create
  99. shell: kubectl create -f /root/k8s/create_admin_user.yaml
  100. tags: init
  101. - name: Create ClusterRoleBinding (K8S Dashboard) Files
  102. copy: src=create_clusterRoleBinding.yaml dest=/root/k8s/create_clusterRoleBinding.yaml owner=root group=root mode=655
  103. tags: init
  104. - name: Create ClusterRoleBinding (K8S Dashboard) - Apply
  105. shell: kubectl create -f /root/k8s/create_clusterRoleBinding.yaml
  106. tags: init
  107. - name: Start K8S Dashboard
  108. shell: kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta6/aio/deploy/recommended.yaml
  109. tags: init
  110. - name: Dump Bearer Token for K8S Dashboard Login
  111. shell: kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > /root/k8s/token
  112. tags: init
  113. #- name: Proxy K8S Dashboard to 8001 on localhost
  114. #shell: nohup kubectl proxy </dev/null >/dev/null 2>&1 &
  115. #tags: init
  116. #- debug: var=init_output.stdout_lines
  117. #tags: init