-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVagrantfile
83 lines (75 loc) · 3.41 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
# Change to add more workers
NodeCount = 1
# Kubernetes Master
config.vm.define "master" do |master|
master.vm.box = "ubuntu/jammy64"
master.vm.synced_folder '.', '/vagrant'
master.vm.hostname = "k3s-master"
master.vm.network "private_network", ip: "192.168.10.100"
master.vm.provider "virtualbox" do |v|
v.name = "k3s-master"
v.memory = 1024
v.cpus = 2
end
master.vm.provision "shell", inline: <<-SHELL
# Modify SSH configuration
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
sed 's@session\\s*required\\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
sed -i 's/KbdInteractiveAuthentication no/KbdInteractiveAuthentication yes/' /etc/ssh/sshd_config
sudo systemctl reload sshd
# Install and configure UFW
sudo apt-get install ufw -y
sudo systemctl start ufw && sudo systemctl enable ufw
sudo ufw allow 22,80,443,6443,9090,10250/tcp
sudo ufw allow 8472,51820/udp
sudo ufw allow 30000:32767/tcp
sudo systemctl restart ufw
# Install K3s
curl -sfL https://get.k3s.io | sh -s - server --node-ip 192.168.10.100 --bind-address 192.168.10.100 --advertise-address 192.168.10.100 --flannel-iface enp0s8
# Get node token for workers to join
sudo chmod 644 /etc/rancher/k3s/k3s.yaml
sudo cat /var/lib/rancher/k3s/server/node-token > /vagrant/node-token
sleep 15
# Taint so only worker ont des pods
kubectl taint nodes k3s-master node-role.kubernetes.io/master:NoSchedule
# Validation
kubectl describe node k3s-master | grep -i taint
SHELL
end
(1..NodeCount).each do |i|
config.vm.define "worker#{i}" do |worker|
worker.vm.box = "ubuntu/jammy64"
worker.vm.synced_folder '.', '/vagrant'
worker.vm.hostname = "k3s-worker#{i}"
worker_ip = "192.168.10.#{i+1}"
worker.vm.network "private_network", ip: worker_ip
worker.vm.provider "virtualbox" do |v|
v.name = "k3s-worker#{i}"
v.memory = 1024
v.cpus = 2
end
worker.vm.provision "shell", env: {"WORKER_IP" => worker_ip}, inline: <<-SHELL
# Modify SSH configuration
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
sed 's@session\\s*required\\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
sed -i 's/KbdInteractiveAuthentication no/KbdInteractiveAuthentication yes/' /etc/ssh/sshd_config
sudo systemctl reload sshd
# Install and configure UFW
sudo apt-get install ufw -y
sudo systemctl start ufw && sudo systemctl enable ufw
sudo ufw allow 22,80,443,6443,9090,10250/tcp
sudo ufw allow 8472,51820/udp
sudo ufw allow 30000:32767/tcp
sudo systemctl restart ufw
# Join K3s cluster
NODE_TOKEN=$(cat /vagrant/node-token)
curl -sfL https://get.k3s.io | K3S_TOKEN=$NODE_TOKEN sh -s - agent --server https://192.168.10.100:6443 --node-ip $WORKER_IP --flannel-iface enp0s8
SHELL
end
end
end