commit b8b9c90868a4e0c7dc32893857d52707628383f0 Author: thebigbone Date: Tue Nov 7 13:58:46 2023 +0530 configs diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..3e65719 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,2 @@ +[default] +inventory = inventory diff --git a/inventory b/inventory new file mode 100644 index 0000000..392318f --- /dev/null +++ b/inventory @@ -0,0 +1,13 @@ +kubecontrol ansible_ssh_private_key_file=~/.ssh/kubeworker ansible_user=kubecontrol + +kubew1 ansible_ssh_private_key_file=~/.ssh/kubew1 ansible_user=kubew1 + +kubew2 ansible_ssh_private_key_file=~/.ssh/kubew2 ansible_user=kubew2 + +[control] +kubecontrol + +[workers] +kubew1 +kubew2 + diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..0eca727 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,84 @@ +- hosts: all + become: yes + + tasks: + - name: update package cache + apt: + update_cache: yes + + - name: install required packages + apt: + name: + - apt-transport-https + - ca-certificates + - curl + - gnupg + - containerd + state: present + + - name: create br_filter + command: modprobe br_filter + + - name: create a containerd directory + file: + path: /etc/containerd + state: directory + + - name: generate containerd default configuration + command: containerd config default + register: containerd_output # Capture the output of the command + + - name: save configuration to /home/kubew2/config.toml + copy: + content: "{{ containerd_output.stdout }}" + dest: $HOME/config.toml + + - name: move it (can't directly create on /etc/containerd for some reason) + command: mv $HOME/config.toml /etc/containerd/config.toml + + + - name: modify containerd.toml + lineinfile: + path: /etc/containerd/config.toml + regexp: '^SystemdCgroup =' + line: 'SystemdCgroup = true' + + - name: turn off swap + command: swapoff -a + + - name: uncomment net.ipv4.ip_forward in sysctl.conf + lineinfile: + path: /etc/sysctl.conf + regexp: '^#?net.ipv4.ip_forward=' + line: 'net.ipv4.ip_forward=1' + state: present + + - name: check if GPG key file exists + stat: + path: /etc/apt/keyrings/kubernetes-apt-keyring.gpg + register: gpg_key_file + + + - name: download Kubernetes GPG key + shell: curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg + when: not gpg_key_file.stat.exists + + + - name: add Kubernetes repository + shell: echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list + + - name: update package cache after adding repository + apt: + update_cache: yes + + - name: install Kubernetes components + apt: + name: + - kubelet + - kubeadm + - kubectl + state: present + + - name: hold Kubernetes packages to prevent automatic updates + command: sudo apt-mark hold kubelet kubeadm kubectl +