From d5cbe8deb0ffd5ee5541fe557e06fb98f9842aaf Mon Sep 17 00:00:00 2001 From: apommier Date: Wed, 19 Feb 2025 19:47:38 +0100 Subject: [PATCH] sort of work but not app3 --- p2/Vagrantfile | 35 ++++++++++++++--------------------- p2/confs/app1.yaml | 32 ++++++++++++++++++++++++++++++++ p2/confs/app2.yaml | 32 ++++++++++++++++++++++++++++++++ p2/confs/app3.yaml | 32 ++++++++++++++++++++++++++++++++ p2/confs/html/app_one.html | 0 p2/confs/ingress.yaml | 32 ++++++++++++++++++++++++++++++++ p2/scripts/deploy.sh | 0 p2/scripts/k3s-master.sh | 11 +++++++++++ 8 files changed, 153 insertions(+), 21 deletions(-) create mode 100644 p2/confs/app1.yaml create mode 100644 p2/confs/app2.yaml create mode 100644 p2/confs/app3.yaml create mode 100644 p2/confs/html/app_one.html create mode 100644 p2/confs/ingress.yaml create mode 100644 p2/scripts/deploy.sh create mode 100644 p2/scripts/k3s-master.sh diff --git a/p2/Vagrantfile b/p2/Vagrantfile index 6d52ade..233775a 100644 --- a/p2/Vagrantfile +++ b/p2/Vagrantfile @@ -1,5 +1,6 @@ Vagrant.configure(2) do |config| config.vm.box = "hashicorp/bionic64" + config.vm.network "forwarded_port", guest: 80, host: 80 config.vm.define "apommierS" do |control| control.vm.hostname = "apommierS" control.vm.network "private_network", ip: "192.168.56.110" @@ -9,26 +10,18 @@ Vagrant.configure(2) do |config| v.cpus = 2 end control.vm.provision "shell", path: "./scripts/k3s-master.sh" + # Deploy Kubernetes manifests + control.vm.provision "shell", inline: <<-SHELL + echo "Waiting for k3s to be ready..." + + echo "Setting KUBECONFIG..." + export KUBECONFIG=/etc/rancher/k3s/k3s.yaml + + echo "Applying Kubernetes deployments..." + kubectl apply -f /vagrant/confs/app1.yaml + kubectl apply -f /vagrant/confs/app2.yaml + kubectl apply -f /vagrant/confs/app3.yaml + kubectl apply -f /vagrant/confs/ingress.yaml + SHELL end - - # config.vm.provision "shell", inline: "" - # control.vm.provision "shell", path: REDACTED - # end - - config.vm.define "apommierSW" do |control| - control.vm.hostname = "apommierSW" - control.vm.network "private_network", ip: "192.168.56.111" - control.vm.provider "virtualbox" do |v| - v.name = "apommierSW" - v.memory = "2048" - v.cpus = 2 - end - control.vm.provision "shell", path: "./scripts/k3s-worker.sh" - end - - # config.vm.provision "shell", inline: <<-SHELL - # [..] - # SHELL - # control.vm.provision "shell", path: REDACTED - # end end \ No newline at end of file diff --git a/p2/confs/app1.yaml b/p2/confs/app1.yaml new file mode 100644 index 0000000..9f97943 --- /dev/null +++ b/p2/confs/app1.yaml @@ -0,0 +1,32 @@ +# app1.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app1 +spec: + replicas: 1 + selector: + matchLabels: + app: app1 + template: + metadata: + labels: + app: app1 + spec: + containers: + - name: app1 + image: containous/whoami + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: app1 +spec: + selector: + app: app1 + ports: + - protocol: TCP + port: 80 + targetPort: 80 diff --git a/p2/confs/app2.yaml b/p2/confs/app2.yaml new file mode 100644 index 0000000..0071584 --- /dev/null +++ b/p2/confs/app2.yaml @@ -0,0 +1,32 @@ +# app2.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app2 +spec: + replicas: 3 + selector: + matchLabels: + app: app2 + template: + metadata: + labels: + app: app2 + spec: + containers: + - name: app2 + image: containous/whoami + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: app2 +spec: + selector: + app: app2 + ports: + - protocol: TCP + port: 80 + targetPort: 80 diff --git a/p2/confs/app3.yaml b/p2/confs/app3.yaml new file mode 100644 index 0000000..3e5af85 --- /dev/null +++ b/p2/confs/app3.yaml @@ -0,0 +1,32 @@ +# app3.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app3 +spec: + replicas: 1 + selector: + matchLabels: + app: app3 + template: + metadata: + labels: + app: app3 + spec: + containers: + - name: app3 + image: containous/whoami + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: app3 +spec: + selector: + app: app3 + ports: + - protocol: TCP + port: 80 + targetPort: 80 diff --git a/p2/confs/html/app_one.html b/p2/confs/html/app_one.html new file mode 100644 index 0000000..e69de29 diff --git a/p2/confs/ingress.yaml b/p2/confs/ingress.yaml new file mode 100644 index 0000000..c2e4401 --- /dev/null +++ b/p2/confs/ingress.yaml @@ -0,0 +1,32 @@ +# ingress.yaml +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: app-ingress +spec: + defaultBackend: + service: + name: app3 + port: + number: 80 + rules: + - host: app1.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: app1 + port: + number: 80 + - host: app2.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: app2 + port: + number: 80 diff --git a/p2/scripts/deploy.sh b/p2/scripts/deploy.sh new file mode 100644 index 0000000..e69de29 diff --git a/p2/scripts/k3s-master.sh b/p2/scripts/k3s-master.sh new file mode 100644 index 0000000..7ba8f2a --- /dev/null +++ b/p2/scripts/k3s-master.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +NODE_IP="192.168.56.110" + +# Install K3s on the master node +curl -sfL https://get.k3s.io | sh -s - --node-ip=$NODE_IP + +# Make sure kubectl is set up for the vagrant user +sudo mkdir -p /home/vagrant/.kube +sudo cp /etc/rancher/k3s/k3s.yaml /home/vagrant/.kube/config +sudo chown -R vagrant:vagrant /home/vagrant/.kube/config \ No newline at end of file