From eba7f8322d853bf35e9736af756632c593e05d1d Mon Sep 17 00:00:00 2001 From: jon brookes Date: Fri, 8 Aug 2025 17:41:57 +0100 Subject: [PATCH] update: remove obsolete traefik service configuration and add playbook for copying K3s config --- scripts/configure_vagrant.sh | 0 scripts/install_traefik.sh | 39 ----------- .../dev/ubuntu/ansible/copy_k8s_config.yaml | 70 +++++++++++++++++++ .../ubuntu/ansible/provision_workstation.sh | 27 +++---- 4 files changed, 79 insertions(+), 57 deletions(-) delete mode 100644 scripts/configure_vagrant.sh create mode 100644 vagrant/dev/ubuntu/ansible/copy_k8s_config.yaml diff --git a/scripts/configure_vagrant.sh b/scripts/configure_vagrant.sh deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/install_traefik.sh b/scripts/install_traefik.sh index a44749a..d021b66 100755 --- a/scripts/install_traefik.sh +++ b/scripts/install_traefik.sh @@ -130,45 +130,6 @@ EOF helm install traefik traefik/traefik --namespace kube-system -f /tmp/traefik-values.yaml fi - - -# cat > traefik-turn-service.yaml << EOF -# apiVersion: v1 -# kind: Service -# metadata: -# name: traefik-turn -# namespace: kube-system -# labels: -# app.kubernetes.io/instance: traefik-traefik -# app.kubernetes.io/name: traefik -# spec: -# type: LoadBalancer -# ports: -# - name: turn-tcp -# port: 1194 -# protocol: TCP -# targetPort: turn-tcp -# - name: turn-udp -# port: 1194 -# protocol: UDP -# targetPort: turn-udp -# selector: -# app.kubernetes.io/instance: traefik-traefik -# app.kubernetes.io/name: traefik -# EOF - -# kubectl apply -f traefik-turn-service.yaml - -# rm -f traefik-turn-service.yaml - - - - - -# echo "Don't forget to create TCP and UDP ingress routes for the TURN server with:" -# echo "kubectl apply -f k8s-manifests/galene/ingressroute-tcp.yaml" -# echo "kubectl apply -f k8s-manifests/galene/ingressroute-udp.yaml" -# echo "" echo "To access the dashboard:" echo "kubectl port-forward -n kube-system \$(kubectl get pods -n kube-system -l \"app.kubernetes.io/name=traefik\" -o name) 9000:9000" echo "Then visit http://localhost:9000/dashboard/ in your browser" \ No newline at end of file diff --git a/vagrant/dev/ubuntu/ansible/copy_k8s_config.yaml b/vagrant/dev/ubuntu/ansible/copy_k8s_config.yaml new file mode 100644 index 0000000..93237d9 --- /dev/null +++ b/vagrant/dev/ubuntu/ansible/copy_k8s_config.yaml @@ -0,0 +1,70 @@ +--- +- name: Copy K3s configuration from vm1 to localhost + hosts: localhost + connection: local + become: true + become_user: root + + tasks: + - name: Ensure .kube directory exists + ansible.builtin.file: + path: /home/vagrant/.kube + state: directory + owner: vagrant + group: vagrant + mode: "0700" + + - name: Copy kubeconfig using scp directly + ansible.builtin.command: > + scp -i ~/.ssh/vm1_key -o StrictHostKeyChecking=no + vagrant@192.168.56.80:/home/vagrant/.kube/config + /home/vagrant/.kube/config + become: false + + - name: Ensure proper ownership + ansible.builtin.file: + path: /home/vagrant/.kube/config + owner: vagrant + group: vagrant + mode: "0600" + become: false + + - name: copy k3s binary to /usr/local/bin/k3s + ansible.builtin.command: > + scp -i ~/.ssh/vm1_key -o StrictHostKeyChecking=no + vagrant@192.168.56.80:/usr/local/bin/k3s + /usr/local/bin/k3s + become: true + + - name: symlink k3s to kubectl + ansible.builtin.file: + src: /usr/local/bin/k3s + dest: /usr/local/bin/kubectl + state: link + become: true + + - name: Ensure KUBECONFIG is set in vagrant .bashrc + ansible.builtin.lineinfile: + path: /home/vagrant/.bashrc + line: "export KUBECONFIG=~/.kube/config" + state: present + insertafter: EOF + owner: vagrant + group: vagrant + mode: "0644" + + - name: Ensure kubectl completion is sourced in vagrant .bashrc + ansible.builtin.lineinfile: + path: /home/vagrant/.bashrc + line: "source <(kubectl completion bash)" + state: present + insertafter: EOF + owner: vagrant + group: vagrant + mode: "0644" + + - name: replace 127.0.0.1:6443 192.168.56.80:6443 in .kube/config + ansible.builtin.replace: + path: /home/vagrant/.kube/config + regexp: "127.0.0.1:6443" + replace: "192.168.56.80:6443" diff --git a/vagrant/dev/ubuntu/ansible/provision_workstation.sh b/vagrant/dev/ubuntu/ansible/provision_workstation.sh index 69edef0..bb92431 100644 --- a/vagrant/dev/ubuntu/ansible/provision_workstation.sh +++ b/vagrant/dev/ubuntu/ansible/provision_workstation.sh @@ -103,23 +103,6 @@ else echo "Provisioning block already present in $BASHRC" fi -echo "" -echo "user id is $(id)" -echo "group id is $(groups)" - -ls -al /home/vagrant/ansible -echo "" -cat /vagrant/ansible/ansible_inventory.ini -echo "" - -echo "root keys" - -ls -al ~/.ssh/vm*_key - -echo "vagrant keys" - -ls -al /home/vagrant/.ssh/vm*_key - ANSIBLE_HOST_KEY_CHECKING=False ansible --inventory-file /home/vagrant/ansible/ansible_inventory.ini -m ping all if [ $? -ne 0 ]; then @@ -136,9 +119,17 @@ 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 | cat +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 +if [ $? -ne 0 ]; then + echo "Ansible playbook failed. Please check your Vagrant VMs and network configuration." + exit 1 +fi + +