main
thebigbone 2023-11-07 13:58:46 +05:30
commit b8b9c90868
3 changed files with 99 additions and 0 deletions

2
ansible.cfg Normal file
View File

@ -0,0 +1,2 @@
[default]
inventory = inventory

13
inventory Normal file
View File

@ -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

84
playbook.yml Normal file
View File

@ -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