diff --git a/pipelines/dev/failing.json b/pipelines/dev/failing.json new file mode 100644 index 0000000..d369347 --- /dev/null +++ b/pipelines/dev/failing.json @@ -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 + } +] diff --git a/scripts/configure_vagrant_k3s.sh b/scripts/configure_vagrant_k3s.sh index 29aabdf..e7ab40a 100755 --- a/scripts/configure_vagrant_k3s.sh +++ b/scripts/configure_vagrant_k3s.sh @@ -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. diff --git a/scripts/dev-pre-flight-checks.sh b/scripts/dev-pre-flight-checks.sh index 4523443..2ffdde6 100755 --- a/scripts/dev-pre-flight-checks.sh +++ b/scripts/dev-pre-flight-checks.sh @@ -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() { diff --git a/scripts/failue.sh b/scripts/failue.sh new file mode 100755 index 0000000..01a9581 --- /dev/null +++ b/scripts/failue.sh @@ -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 diff --git a/vagrant/dev/ubuntu/Vagrantfile b/vagrant/dev/ubuntu/Vagrantfile index 98fc79d..b813bce 100644 --- a/vagrant/dev/ubuntu/Vagrantfile +++ b/vagrant/dev/ubuntu/Vagrantfile @@ -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 diff --git a/vagrant/dev/ubuntu/ansible/install_k3s_3node.yaml b/vagrant/dev/ubuntu/ansible/install_k3s_3node.yaml index bd96230..a8ed7b3 100644 --- a/vagrant/dev/ubuntu/ansible/install_k3s_3node.yaml +++ b/vagrant/dev/ubuntu/ansible/install_k3s_3node.yaml @@ -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 diff --git a/vagrant/dev/ubuntu/ansible/install_longhorn_prereqs.yaml b/vagrant/dev/ubuntu/ansible/install_longhorn_prereqs.yaml new file mode 100644 index 0000000..c22a182 --- /dev/null +++ b/vagrant/dev/ubuntu/ansible/install_longhorn_prereqs.yaml @@ -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' }}" \ No newline at end of file diff --git a/vagrant/dev/ubuntu/ansible/provision_workstation.sh b/vagrant/dev/ubuntu/ansible/provision_workstation.sh index 45605b7..2d95d67 100644 --- a/vagrant/dev/ubuntu/ansible/provision_workstation.sh +++ b/vagrant/dev/ubuntu/ansible/provision_workstation.sh @@ -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 diff --git a/vagrant/dev/ubuntu/k8s/nginx-test/deployment.yaml b/vagrant/dev/ubuntu/k8s/nginx-test/deployment.yaml new file mode 100644 index 0000000..63ec4fe --- /dev/null +++ b/vagrant/dev/ubuntu/k8s/nginx-test/deployment.yaml @@ -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 diff --git a/vagrant/dev/ubuntu/k8s/nginx-test/pvc.yaml b/vagrant/dev/ubuntu/k8s/nginx-test/pvc.yaml new file mode 100644 index 0000000..9816354 --- /dev/null +++ b/vagrant/dev/ubuntu/k8s/nginx-test/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: nginx-data-pvc + namespace: default +spec: + accessModes: + - ReadWriteOnce + storageClassName: longhorn + resources: + requests: + storage: 1Gi diff --git a/vagrant/dev/ubuntu/scripts/install_vagrant_longhorn.sh b/vagrant/dev/ubuntu/scripts/install_vagrant_longhorn.sh new file mode 100755 index 0000000..368519c --- /dev/null +++ b/vagrant/dev/ubuntu/scripts/install_vagrant_longhorn.sh @@ -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