Added k3s
This commit is contained in:
46
.gitignore
vendored
Executable file
46
.gitignore
vendored
Executable file
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
# Created by https://www.gitignore.io/api/macos,vagrant,visualstudiocode
|
||||||
|
|
||||||
|
### macOS ###
|
||||||
|
*.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
### Vagrant ###
|
||||||
|
.vagrant/
|
||||||
|
*.box
|
||||||
|
|
||||||
|
### VisualStudioCode ###
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.history
|
||||||
|
|
||||||
|
### Ansible ###
|
||||||
|
*.retry
|
||||||
|
|
||||||
|
# End of https://www.gitignore.io/api/macos,vagrant,visualstudiocode,ansible
|
||||||
63
README.md
Normal file
63
README.md
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
[](http://www.agile611.com/)
|
||||||
|
# Start Using Kubernetes (k3s) with Vagrant
|
||||||
|
|
||||||
|
Aquest repositori mostra com desplegar un clúster lleuger de Kubernetes (k3s) usant Vagrant per a desenvolupament i proves ràpides.
|
||||||
|
|
||||||
|
**Prerequisits**
|
||||||
|
|
||||||
|
- Vagrant instal·lat
|
||||||
|
- Un provider de VM (VirtualBox, Parallels, o un provider suportat)
|
||||||
|
- `curl` i `ssh` disponibles
|
||||||
|
|
||||||
|
Consulteu el `Vagrantfile` per a configuracions específiques del provider.
|
||||||
|
|
||||||
|
**Ràpid Inici**
|
||||||
|
|
||||||
|
1. Arrancar les màquines amb Vagrant:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vagrant up
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Comprovar l'estat del clúster (ssh a una màquina i utilitzar `kubectl` integrat):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vagrant ssh -c "sudo kubectl get nodes"
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Parar i eliminar les màquines:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vagrant halt
|
||||||
|
vagrant destroy -f
|
||||||
|
```
|
||||||
|
|
||||||
|
**Detalls d'instal·lació**
|
||||||
|
|
||||||
|
Les instruccions d'instal·lació i els scripts utilitzats per configurar k3s estan a [install_k3s.txt](install_k3s.txt). Revisa aquest fitxer per entendre com s'instal·la i s'inicia k3s dins de les VM.
|
||||||
|
|
||||||
|
**Personalitzar**
|
||||||
|
|
||||||
|
Modifica el [Vagrantfile](Vagrantfile) per canviar la mida de la VM, la xarxa o el nombre de nodes.
|
||||||
|
|
||||||
|
**Contribucions i errors**
|
||||||
|
|
||||||
|
Obre un issue o envia un PR amb millores o problemes trobats.
|
||||||
|
|
||||||
|
# Support
|
||||||
|
|
||||||
|
This tutorial is released into the public domain by [Agile611](http://www.agile611.com/) under Creative Commons Attribution-NonCommercial 4.0 International.
|
||||||
|
|
||||||
|
[](https://creativecommons.org/licenses/by-nc/4.0/)
|
||||||
|
|
||||||
|
|
||||||
|
This README file was originally written by [Guillem Hernández Sola](https://www.linkedin.com/in/guillemhs/) and is likewise released into the public domain.
|
||||||
|
|
||||||
|
Please contact Agile611 for further details.
|
||||||
|
|
||||||
|
* [Agile611](http://www.agile611.com/)
|
||||||
|
* Laureà Miró 309
|
||||||
|
* 08950 Esplugues de Llobregat (Barcelona)
|
||||||
|
|
||||||
|
[](http://www.agile611.com/)
|
||||||
|
|
||||||
78
Vagrantfile
vendored
Normal file
78
Vagrantfile
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
NUM_WORKER_NODES=2
|
||||||
|
IP_NW="192.0.3."
|
||||||
|
IP_START=10
|
||||||
|
|
||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.vm.box = "bento/ubuntu-24.04"
|
||||||
|
config.vm.box_check_update = true
|
||||||
|
|
||||||
|
config.vm.define "master" do |master|
|
||||||
|
master.vm.hostname = "master-node"
|
||||||
|
master.vm.network "private_network", ip: IP_NW + "#{IP_START}"
|
||||||
|
master.vm.provider "virtualbox" do |vb|
|
||||||
|
vb.memory = 4048
|
||||||
|
vb.cpus = 2
|
||||||
|
end
|
||||||
|
master.vm.provision "shell", path: "install_k3s.sh"
|
||||||
|
master.vm.network :forwarded_port, guest: 8001, host: 8001
|
||||||
|
master.vm.network :forwarded_port, guest: 6443, host: 6443
|
||||||
|
for i in 30000..32767
|
||||||
|
master.vm.network :forwarded_port, guest: i, host: i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
(1..NUM_WORKER_NODES).each do |i|
|
||||||
|
|
||||||
|
config.vm.define "node0#{i}" do |node|
|
||||||
|
node.vm.hostname = "worker-node0#{i}"
|
||||||
|
node.vm.network "private_network", ip: IP_NW + "#{IP_START + i}"
|
||||||
|
node.vm.provider "virtualbox" do |vb|
|
||||||
|
vb.memory = 2048
|
||||||
|
vb.cpus = 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Configuració Global
|
||||||
|
NUM_WORKER_NODES = 2
|
||||||
|
IP_NW = "192.0.3."
|
||||||
|
IP_MASTER = "192.0.3.10" # Fixem la IP del Master per referenciar-la als workers
|
||||||
|
|
||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.vm.box = "bento/ubuntu-24.04"
|
||||||
|
config.vm.box_check_update = false
|
||||||
|
|
||||||
|
# --- Configuració del MASTER ---
|
||||||
|
config.vm.define "master" do |master|
|
||||||
|
master.vm.hostname = "master-node"
|
||||||
|
master.vm.network "private_network", ip: IP_MASTER
|
||||||
|
|
||||||
|
master.vm.provider "virtualbox" do |vb|
|
||||||
|
vb.memory = 2048 # Amb 2GB n'hi ha prou per K3s bàsic
|
||||||
|
vb.cpus = 2
|
||||||
|
end
|
||||||
|
|
||||||
|
# Ports importants (API i Ingress HTTP/HTTPS)
|
||||||
|
master.vm.network :forwarded_port, guest: 6443, host: 6443, id: "k8s-api"
|
||||||
|
master.vm.network :forwarded_port, guest: 80, host: 8080, id: "ingress-http" # Accedeix a les apps via localhost:8080
|
||||||
|
|
||||||
|
master.vm.provision "shell", path: "k3s_master.sh"
|
||||||
|
end
|
||||||
|
|
||||||
|
# --- Configuració dels WORKERS ---
|
||||||
|
(1..NUM_WORKER_NODES).each do |i|
|
||||||
|
config.vm.define "node0#{i}" do |node|
|
||||||
|
node.vm.hostname = "worker-node0#{i}"
|
||||||
|
node.vm.network "private_network", ip: IP_NW + "#{10 + i}"
|
||||||
|
|
||||||
|
node.vm.provider "virtualbox" do |vb|
|
||||||
|
vb.memory = 1024 # 1GB per worker
|
||||||
|
vb.cpus = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
node.vm.provision "shell", path: "k3s_worker.sh"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
9
k3s_master.sh
Normal file
9
k3s_master.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
echo "🚀 Instal·lant K3s Server (Master)..."
|
||||||
|
curl -sfL https://get.k3s.io | sh -s - --node-ip #{IP_MASTER} --flannel-iface eth1
|
||||||
|
|
||||||
|
echo "🔑 Guardant el Token a la carpeta compartida..."
|
||||||
|
# Copiem el token a /vagrant (que és la carpeta del teu PC) perquè els workers el vegin
|
||||||
|
sudo cp /var/lib/rancher/k3s/server/node-token /vagrant/node-token
|
||||||
|
sudo chmod 644 /vagrant/node-token
|
||||||
|
|
||||||
|
echo "✅ Master llest!"
|
||||||
10
k3s_worker.sh
Normal file
10
k3s_worker.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
echo "⏳ Esperant que el Master generi el token..."
|
||||||
|
while [ ! -f /vagrant/node-token ]; do sleep 2; done
|
||||||
|
|
||||||
|
K3S_TOKEN=$(cat /vagrant/node-token)
|
||||||
|
NODE_IP=$(ip addr show eth1 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
|
||||||
|
|
||||||
|
echo "🚀 Instal·lant K3s Agent (Worker) connectant a #{IP_MASTER}..."
|
||||||
|
curl -sfL https://get.k3s.io | K3S_URL=https://#{IP_MASTER}:6443 K3S_TOKEN=$K3S_TOKEN sh -s - --node-ip $NODE_IP --flannel-iface eth1
|
||||||
|
|
||||||
|
echo "✅ Worker unit al clúster!"
|
||||||
Reference in New Issue
Block a user