update: Added Longhorn installation process and updated memory allocation for VMs

update: Added 'git' and 'vagrant' to required tools in pre-flight checks

fix: configured k3s install to use internal nic for flanel network
This commit is contained in:
jon brookes 2025-08-16 18:00:28 +01:00
parent d839fd5687
commit 1605aa4f90
11 changed files with 220 additions and 13 deletions

View file

@ -55,7 +55,7 @@
- name: Install k3s on first node
ansible.builtin.shell: |
set -o pipefail
K3S_TOKEN=$(cat /opt/k3s-token) /bin/bash /tmp/k3s_install.sh server --cluster-init --disable traefik --disable servicelb --tls-san {{ k3s_url_ip }} --node-name vm1 --node-ip {{ vm1_ip }}
K3S_TOKEN=$(cat /opt/k3s-token) /bin/bash /tmp/k3s_install.sh server --cluster-init --disable traefik --disable servicelb --tls-san {{ k3s_url_ip }} --node-name vm1 --node-ip {{ vm1_ip }} --flannel-iface=enp0s8
if [ $? -eq 0 ]; then
mkdir -p /home/vagrant/.kube && cp /etc/rancher/k3s/k3s.yaml /home/vagrant/.kube/config && chown vagrant:vagrant /home/vagrant/.kube/config
fi
@ -91,7 +91,7 @@
{% endif %}
K3S_URL=https://{{ k3s_url_ip }}:6443 \
K3S_TOKEN={{ k3s_token_content.stdout }} \
INSTALL_K3S_EXEC="server --server https://{{ k3s_url_ip }}:6443 --disable traefik --disable servicelb --node-name={{ inventory_hostname }} --node-ip ${NODE_IP}" \
INSTALL_K3S_EXEC="server --server https://{{ k3s_url_ip }}:6443 --disable traefik --disable servicelb --node-name={{ inventory_hostname }} --node-ip ${NODE_IP} --flannel-iface=enp0s8" \
/bin/bash /tmp/k3s_install.sh 2>&1
exit_code=$?
if [ $exit_code -ne 0 ]; then

View file

@ -0,0 +1,47 @@
---
- name: Install k3s on 3-node cluster
hosts: vm1,vm2,vm3
become: true
become_user: root
serial: 1 # Ensure tasks are executed one host at a time
vars_files:
- vars.yaml
tasks:
- name: Install open-iscsi on all nodes
ansible.builtin.package:
name: open-iscsi
state: present
- name: Install nfs-common on all nodes
ansible.builtin.package:
name: nfs-common
state: present
- name: Install cryptsetup and dmsetup packages
ansible.builtin.package:
name:
- cryptsetup
- dmsetup
state: present
- name: Load dm_crypt kernel module
community.general.modprobe:
name: dm_crypt
state: present
- name: Make dm_crypt module load on boot
ansible.builtin.lineinfile:
path: /etc/modules
line: dm_crypt
create: yes
- name: Check if dm_crypt module is loaded
ansible.builtin.shell: lsmod | grep dm_crypt
register: dm_crypt_check
failed_when: false
changed_when: false
- name: Show dm_crypt status
ansible.builtin.debug:
msg: "dm_crypt module is {{ 'loaded' if dm_crypt_check.rc == 0 else 'not loaded' }}"

View file

@ -3,7 +3,6 @@
sudo apt-get update
sudo apt-get install -y software-properties-common git vim python3.10-venv
# Set up ansible environment for vagrant user
sudo -u vagrant mkdir -p /home/vagrant/.ansible
sudo -u vagrant touch /home/vagrant/.ansible/ansible.cfg
@ -103,7 +102,20 @@ else
echo "Provisioning block already present in $BASHRC"
fi
ANSIBLE_HOST_KEY_CHECKING=False ansible --inventory-file /home/vagrant/ansible/ansible_inventory.ini -m ping vm1,vm2,vm3
echo
echo -------------------------
echo
su - vagrant
id
echo
echo -------------------------
echo
ssh-add ~/.ssh/vm*_key
ANSIBLE_SUPPRESS_INTERPRETER_DISCOVERY_WARNING=1 ANSIBLE_HOST_KEY_CHECKING=False ansible --inventory-file /home/vagrant/ansible/ansible_inventory.ini -m ping vm1,vm2,vm3
if [ $? -ne 0 ]; then
echo "Ansible ping failed. Please check your Vagrant VMs and network configuration."
@ -111,7 +123,7 @@ if [ $? -ne 0 ]; then
fi
# install_keepalived.yaml
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook install_keepalived.yaml --inventory-file ansible_inventory.ini
ANSIBLE_SUPPRESS_INTERPRETER_DISCOVERY_WARNING=1 ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook install_keepalived.yaml --inventory-file ansible_inventory.ini
if [ $? -ne 0 ]; then
echo "Ansible playbook failed. Please check your Vagrant VMs and network configuration."
exit 1
@ -119,14 +131,14 @@ fi
echo "Keepalived installation completed."
# install_k3s_3node.yaml
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook install_k3s_3node.yaml --inventory-file ansible_inventory.ini
ANSIBLE_SUPPRESS_INTERPRETER_DISCOVERY_WARNING=1 ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook install_k3s_3node.yaml --inventory-file ansible_inventory.ini
if [ $? -ne 0 ]; then
echo "Ansible playbook failed. Please check your Vagrant VMs and network configuration."
exit 1
fi
# copy_k8s_config.yaml
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook copy_k8s_config.yaml --inventory-file ansible_inventory.ini
ANSIBLE_SUPPRESS_INTERPRETER_DISCOVERY_WARNING=1ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook copy_k8s_config.yaml --inventory-file ansible_inventory.ini
if [ $? -ne 0 ]; then
echo "Ansible playbook failed. Please check your Vagrant VMs and network configuration."
exit 1