summaryrefslogtreecommitdiffstats
path: root/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks')
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-flannel.yml8
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-master.yml22
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-workers-drain.yml8
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-workers-reset.yml11
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-kubevirt-ovs.yml8
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-multus.yml8
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-sriov.yml30
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-userspace.yml8
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/cni-pre-deploy.yml17
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/configure_master_node.yml14
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-flannel.yml11
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-kubevirt-ovs.yml12
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-multus.yml10
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-sriov.yml26
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-userspace.yml13
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/foldersettings.yml10
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/main.yml83
-rw-r--r--tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/workers.yml15
18 files changed, 314 insertions, 0 deletions
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-flannel.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-flannel.yml
new file mode 100644
index 00000000..9d0ffda4
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-flannel.yml
@@ -0,0 +1,8 @@
+---
+
+- name: Delete Kube-flannel
+ k8s:
+ state: absent
+ definition: "{{ lookup('file', 'kube-flannel-daemonset.yml') }}"
+
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-master.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-master.yml
new file mode 100644
index 00000000..f797ddb6
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-master.yml
@@ -0,0 +1,22 @@
+---
+- name: Drain master node
+ command: kubectl drain {{ ansible_hostname }} --delete-local-data --force --ignore-daemonsets
+
+- name: Delete master node
+ command: kubectl delete node {{ ansible_hostname }}
+
+- name: Kubeadm reset (master)
+ shell: yes y | sudo kubeadm reset
+
+- name: Delete /etc/cni/net.d/ (master)
+ command: sudo rm -rf /etc/cni/net.d/
+
+- name: Delete $HOME/.kube/
+ file:
+ path: $HOME/.kube/
+ state: absent
+
+- name: Delete init log file
+ file:
+ path: "{{ token_file }}"
+ state: absent \ No newline at end of file
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-workers-drain.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-workers-drain.yml
new file mode 100644
index 00000000..46ae50ec
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-workers-drain.yml
@@ -0,0 +1,8 @@
+---
+- name: Drain worker node
+ delegate_to: "{{ groups['master'][0] }}"
+ command: kubectl drain {{ ansible_hostname }} --delete-local-data --force --ignore-daemonsets
+
+- name: Delete worker node
+ delegate_to: "{{ groups['master'][0] }}"
+ command: kubectl delete node {{ ansible_hostname }}
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-workers-reset.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-workers-reset.yml
new file mode 100644
index 00000000..62a8c01f
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-k8s-workers-reset.yml
@@ -0,0 +1,11 @@
+---
+- name: Kubeadm reset (worker)
+ shell: yes y | sudo kubeadm reset
+
+- name: Delete /etc/cni/net.d/ (worker)
+ command: sudo rm -rf /etc/cni/net.d/
+
+- name: Remove node_joined.txt
+ file:
+ path: $HOME/node_joined.txt
+ state: absent \ No newline at end of file
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-kubevirt-ovs.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-kubevirt-ovs.yml
new file mode 100644
index 00000000..30740a44
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-kubevirt-ovs.yml
@@ -0,0 +1,8 @@
+---
+
+- name: Delete ovs-cni-plugin
+ k8s:
+ state: absent
+ definition: "{{ lookup('file', 'ovs-daemonset.yml') }}"
+
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-multus.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-multus.yml
new file mode 100644
index 00000000..44eabbd1
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-multus.yml
@@ -0,0 +1,8 @@
+---
+
+- name: Delete Multus
+ k8s:
+ state: absent
+ definition: "{{ lookup('file', 'multus-daemonset.yml') }}"
+
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-sriov.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-sriov.yml
new file mode 100644
index 00000000..6d725ce8
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-sriov.yml
@@ -0,0 +1,30 @@
+---
+
+- name: Delete SRIOV CNI Daemonset
+ k8s:
+ state: absent
+ apply: yes
+ definition: "{{ lookup('file', 'sriov-cni-daemonset.yaml') }}"
+
+- name: Delete SRIOV Device Plugin
+ k8s:
+ state: absent
+ apply: yes
+ definition: "{{ lookup('file', 'sriov-device-plugin-daemonset.yaml') }}"
+
+- name: Deploy SRIOV Device Plugin Config
+ k8s:
+ state: absent
+ apply: yes
+ definition: "{{ lookup('file', 'configMap-sriov-device-plugin.yaml') }}"
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-userspace.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-userspace.yml
new file mode 100644
index 00000000..72b3d869
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/clear-userspace.yml
@@ -0,0 +1,8 @@
+---
+
+- name: Delete userspace-cni plugin
+ k8s:
+ state: absent
+ definition: "{{ lookup('file', 'userspace-daemonset.yml') }}"
+
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/cni-pre-deploy.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/cni-pre-deploy.yml
new file mode 100644
index 00000000..b2f280ef
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/cni-pre-deploy.yml
@@ -0,0 +1,17 @@
+---
+- name: Install openshift python package
+ pip:
+ name: openshift
+ executable: "{{ PIP_executable_version }}"
+ when: inventory_hostname in groups['master']
+ become: yes
+
+- name: Check whether /etc/cni/net.d/ exists
+ stat:
+ path: /etc/cni/net.d
+ register: files_to_delete
+
+- name: Delete /etc/cni/net.d/
+ become: yes
+ command: sudo rm -r /etc/cni/net.d/
+ when: files_to_delete.stat.exists and files_to_delete.stat.isdir \ No newline at end of file
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/configure_master_node.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/configure_master_node.yml
new file mode 100644
index 00000000..4980e17e
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/configure_master_node.yml
@@ -0,0 +1,14 @@
+---
+- name: Pulling images required for setting up a Kubernetes cluster
+ become: yes
+ command: kubeadm config images pull
+
+- name: Initializing Kubernetes cluster
+ become: yes
+ command: kubeadm init --apiserver-advertise-address={{ kube_ad_addr }} --pod-network-cidr={{ kube_cidr_v }}
+ register: output
+
+- name: Storing Logs and Generated token for future purpose.
+ copy:
+ content: "{{ output.stdout }}"
+ dest: "{{ token_file }}" \ No newline at end of file
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-flannel.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-flannel.yml
new file mode 100644
index 00000000..367d682f
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-flannel.yml
@@ -0,0 +1,11 @@
+---
+
+- name: Clean flannel
+ import_tasks: clear-flannel.yml
+
+- name: Deploy Kube-flannel
+ k8s:
+ state: present
+ definition: "{{ lookup('file', 'kube-flannel-daemonset.yml') }}"
+ wait: yes
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-kubevirt-ovs.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-kubevirt-ovs.yml
new file mode 100644
index 00000000..9913cae4
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-kubevirt-ovs.yml
@@ -0,0 +1,12 @@
+---
+
+- name: Clean kubevirt-ovs
+ include: clear-kubevirt-ovs.yml
+
+- name: Deploy ovs-cni-plugin
+ k8s:
+ state: present
+ apply: yes
+ definition: "{{ lookup('file', 'ovs-daemonset.yml') }}"
+
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-multus.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-multus.yml
new file mode 100644
index 00000000..6fb77e42
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-multus.yml
@@ -0,0 +1,10 @@
+---
+
+- name: Clear Multus
+ include: clear-multus.yml
+
+- name: Deploy Multus
+ k8s:
+ state: present
+ definition: "{{ lookup('file', 'multus-daemonset.yml') }}"
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-sriov.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-sriov.yml
new file mode 100644
index 00000000..aaff5cf0
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-sriov.yml
@@ -0,0 +1,26 @@
+---
+
+- name: clean sriov
+ include: clear-sriov.yml
+
+- name: Deploy SRIOV Device Plugin Config
+ k8s:
+ state: present
+ apply: yes
+ definition: "{{ lookup('file', 'configMap-sriov-device-plugin.yaml') }}"
+ wait: yes
+
+- name: Deploy SRIOV Device Plugin
+ k8s:
+ state: present
+ apply: yes
+ definition: "{{ lookup('file', 'sriov-device-plugin-daemonset.yaml') }}"
+
+- name: Deploy SRIOV CNI
+ k8s:
+ state: present
+ apply: yes
+ definition: "{{ lookup('file', 'sriov-cni-daemonset.yaml') }}"
+
+
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-userspace.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-userspace.yml
new file mode 100644
index 00000000..32e3b9b1
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/deploy-userspace.yml
@@ -0,0 +1,13 @@
+---
+
+- name: Clean userspace-cni
+ include: clear-userspace.yml
+
+- name: Deploy userspace-cni plugin
+ k8s:
+ state: present
+ apply: yes
+ definition: "{{ lookup('file', 'userspace-daemonset.yml') }}"
+
+
+
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/foldersettings.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/foldersettings.yml
new file mode 100644
index 00000000..1a8c1879
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/foldersettings.yml
@@ -0,0 +1,10 @@
+---
+- name: .kube directory creation in $HOME/
+ file:
+ path: $HOME/.kube
+ state: directory
+
+- name: Copying required files
+ shell: |
+ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
+ sudo chown $(id -u):$(id -g) $HOME/.kube/config \ No newline at end of file
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/main.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/main.yml
new file mode 100644
index 00000000..28c3f501
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/main.yml
@@ -0,0 +1,83 @@
+- name: include master tasks
+ import_tasks: configure_master_node.yml
+ when: inventory_hostname in groups['master']
+ tags: deploy
+
+- name: include folder settings for kube config
+ import_tasks: foldersettings.yml
+ when: inventory_hostname in groups['master']
+ tags: deploy
+
+- name: include join worker tasks
+ import_tasks: workers.yml
+ when: inventory_hostname in groups['workers']
+ tags: deploy, join
+
+- name: cni pre-deploy
+ import_tasks: cni-pre-deploy.yml
+ tags: deploy, cni
+
+- name: deploy flannel
+ import_tasks: deploy-flannel.yml
+ when: inventory_hostname in groups['master']
+ tags: deploy, cni
+
+- name: clear flannel
+ import_tasks: clear-flannel.yml
+ when: inventory_hostname in groups['master']
+ tags: clear
+
+- name: deploy multus
+ import_tasks: deploy-multus.yml
+ when: inventory_hostname in groups['master']
+ tags: deploy, cni
+
+- name: clear multus
+ import_tasks: clear-multus.yml
+ when: inventory_hostname in groups['master']
+ tags: clear
+
+- name: deploy kubevirt-ovs
+ import_tasks: deploy-kubevirt-ovs.yml
+ when: inventory_hostname in groups['master']
+ tags: deploy, cni
+
+- name: clear kubevirt-ovs
+ import_tasks: clear-kubevirt-ovs.yml
+ when: inventory_hostname in groups['master']
+ tags: clear
+
+- name: deploy sriov
+ import_tasks: deploy-sriov.yml
+ when: inventory_hostname in groups['master']
+ tags: deploy, cni
+
+- name: clear sriov
+ import_tasks: clear-sriov.yml
+ when: inventory_hostname in groups['master']
+ tags: clear
+
+- name: deploy userspace
+ import_tasks: deploy-userspace.yml
+ when: inventory_hostname in groups['master']
+ tags: deploy, cni
+
+- name: clear userspace
+ import_tasks: clear-userspace.yml
+ when: inventory_hostname in groups['master']
+ tags: clear
+
+- name: drain and delete workers from master
+ import_tasks: clear-k8s-workers-drain.yml
+ when: inventory_hostname in groups['workers']
+ tags: clear
+
+- name: reset workers
+ import_tasks: clear-k8s-workers-reset.yml
+ when: inventory_hostname in groups['workers']
+ tags: clear
+
+- name: clear master
+ import_tasks: clear-k8s-master.yml
+ when: inventory_hostname in groups['master']
+ tags: clear \ No newline at end of file
diff --git a/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/workers.yml b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/workers.yml
new file mode 100644
index 00000000..a0a815c4
--- /dev/null
+++ b/tools/k8s/cluster-deployment/k8scluster/roles/clustermanager/tasks/workers.yml
@@ -0,0 +1,15 @@
+---
+- name: check node is already in cluster
+ delegate_to: "{{ groups.master[0] }}"
+ command: "kubectl get nodes -n kube-system -o name"
+ register: get_node_register
+ changed_when: false
+
+- name: get join command
+ delegate_to: "{{ groups.master[0] }}"
+ command: kubeadm token create --print-join-command
+ register: join_command_raw
+
+- name: join cluster
+ shell: "sudo {{ join_command_raw.stdout_lines[0] }} --ignore-preflight-errors=all > $HOME/node_joined.txt"
+ when: ( 'node/' + ansible_hostname ) not in get_node_register.stdout_lines