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:
parent
d839fd5687
commit
1605aa4f90
11 changed files with 220 additions and 13 deletions
33
pipelines/dev/failing.json
Normal file
33
pipelines/dev/failing.json
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
[
|
||||
|
||||
{
|
||||
"name": "Create Vagrant nodes",
|
||||
"function": "RunCommand",
|
||||
"params": [
|
||||
"./scripts/failue.sh"
|
||||
],
|
||||
"retryCount": 0,
|
||||
"shouldAbort": true
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Configure Vagrant K3s",
|
||||
"function": "RunCommand",
|
||||
"params": [
|
||||
"./scripts/configure_vagrant_k3s.sh"
|
||||
],
|
||||
"retryCount": 0,
|
||||
"shouldAbort": true
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
"name": "Create Vagrant workstation",
|
||||
"function": "RunCommand",
|
||||
"params": [
|
||||
"./scripts/install_vagrant_workstation.sh"
|
||||
],
|
||||
"retryCount": 0,
|
||||
"shouldAbort": true
|
||||
}
|
||||
]
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# set -euo pipefail
|
||||
|
||||
# This script checks for Vagrant and VirtualBox prerequisites,
|
||||
# ensures Vagrant VMs are running, and gathers network and
|
||||
# system information from the VMs.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
required_tools=("infctl" "pwgen" "kubectl" "k3d" "helm" "jq" "docker")
|
||||
required_tools=("infctl" "pwgen" "kubectl" "k3d" "helm" "jq" "git" "docker" "vagrant")
|
||||
|
||||
MISSING=false
|
||||
check_required_tools() {
|
||||
|
|
|
|||
24
scripts/failue.sh
Executable file
24
scripts/failue.sh
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
echo "crash"
|
||||
|
||||
sleep 1
|
||||
|
||||
echo "bang"
|
||||
|
||||
sleep 2
|
||||
|
||||
echo "wallop"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
|
||||
echo "Houston, we have a problem"
|
||||
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
|
||||
exit 1
|
||||
6
vagrant/dev/ubuntu/Vagrantfile
vendored
6
vagrant/dev/ubuntu/Vagrantfile
vendored
|
|
@ -34,7 +34,7 @@ Vagrant.configure("2") do |config|
|
|||
end
|
||||
|
||||
vm1.vm.provider "virtualbox" do |vb|
|
||||
vb.memory = "2048" # 2GB memory
|
||||
vb.memory = "4096" # 4GB memory
|
||||
vb.cpus = 2
|
||||
end
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ Vagrant.configure("2") do |config|
|
|||
end
|
||||
|
||||
vm2.vm.provider "virtualbox" do |vb|
|
||||
vb.memory = "2048" # 2GB memory
|
||||
vb.memory = "4096" # 4GB memory
|
||||
vb.cpus = 2
|
||||
end
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ Vagrant.configure("2") do |config|
|
|||
end
|
||||
|
||||
vm3.vm.provider "virtualbox" do |vb|
|
||||
vb.memory = "2048" # 2GB memory
|
||||
vb.memory = "4096" # 4GB memory
|
||||
vb.cpus = 2
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
47
vagrant/dev/ubuntu/ansible/install_longhorn_prereqs.yaml
Normal file
47
vagrant/dev/ubuntu/ansible/install_longhorn_prereqs.yaml
Normal 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' }}"
|
||||
|
|
@ -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
|
||||
|
|
|
|||
27
vagrant/dev/ubuntu/k8s/nginx-test/deployment.yaml
Normal file
27
vagrant/dev/ubuntu/k8s/nginx-test/deployment.yaml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-with-storage
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx-storage
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx-storage
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:stable
|
||||
ports:
|
||||
- containerPort: 80
|
||||
volumeMounts:
|
||||
- name: nginx-data
|
||||
mountPath: /usr/share/nginx/html
|
||||
volumes:
|
||||
- name: nginx-data
|
||||
persistentVolumeClaim:
|
||||
claimName: nginx-data-pvc
|
||||
12
vagrant/dev/ubuntu/k8s/nginx-test/pvc.yaml
Normal file
12
vagrant/dev/ubuntu/k8s/nginx-test/pvc.yaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: nginx-data-pvc
|
||||
namespace: default
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
storageClassName: longhorn
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
54
vagrant/dev/ubuntu/scripts/install_vagrant_longhorn.sh
Executable file
54
vagrant/dev/ubuntu/scripts/install_vagrant_longhorn.sh
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
echo
|
||||
echo "vagrant longhorn installation"
|
||||
echo
|
||||
|
||||
ssh-add ~/.ssh/vm*_key
|
||||
source /home/vagrant/ansible/venv/bin/activate
|
||||
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."
|
||||
exit 1
|
||||
fi
|
||||
echo "Ansible ping successful."
|
||||
|
||||
# Check if there are any pods in the longhorn-system namespace
|
||||
if kubectl -n longhorn-system get pods --no-headers 2>/dev/null | grep -q '^[^ ]'; then
|
||||
echo "Pods already exist in the longhorn-system namespace. Skipping installation."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Installing Longhorn prerequisites..."
|
||||
|
||||
|
||||
# install_longhorn_prereqs.yaml
|
||||
ANSIBLE_SUPPRESS_INTERPRETER_DISCOVERY_WARNING=1 ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook ~/ansible/install_longhorn_prereqs.yaml --inventory-file /home/vagrant/ansible/ansible_inventory.ini
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Ansible playbook failed. Please check the playbook and your inventory."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "installing Longhorn ..."
|
||||
|
||||
# https://github.com/longhorn/longhorn/releases
|
||||
# v1.8.1 in prod 1.9.1 is latest
|
||||
LONGHORN_RELEASE="v1.8.1"
|
||||
LONGHORN_RELEASE_URL="https://raw.githubusercontent.com/longhorn/longhorn/$LONGHORN_RELEASE/deploy/longhorn.yaml"
|
||||
|
||||
echo "Applying Longhorn release $LONGHORN_RELEASE..."
|
||||
echo "Using Longhorn release URL: $LONGHORN_RELEASE_URL"
|
||||
|
||||
kubectl apply -f $LONGHORN_RELEASE_URL
|
||||
|
||||
# Wait for all pods in longhorn-system namespace to be ready
|
||||
echo "Waiting for Longhorn pods to be ready..."
|
||||
while true; do
|
||||
not_ready=$(kubectl -n longhorn-system get pods --no-headers 2>/dev/null | grep -vE 'Running|Completed' | wc -l)
|
||||
total=$(kubectl -n longhorn-system get pods --no-headers 2>/dev/null | wc -l)
|
||||
if [[ $total -gt 0 && $not_ready -eq 0 ]]; then
|
||||
echo "All Longhorn pods are ready."
|
||||
break
|
||||
fi
|
||||
sleep 10
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue