├── .gitignore ├── init ├── init_worker.sh └── init_master.sh ├── README.md └── Vagrantfile /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | tmp/ -------------------------------------------------------------------------------- /init/init_worker.sh: -------------------------------------------------------------------------------- 1 | echo "Install K3S Nodes" 2 | 3 | TOKEN=`cat /vagrant/tmp/node-token` 4 | MASTER_IP=`getent hosts master|awk '{print $1}'` 5 | ETH="enp0s8" 6 | echo "TOKEN : "$TOKEN 7 | echo "Master IP : "$MASTER_IP 8 | echo "Flannel eth : "$ETH 9 | 10 | curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-iface=$ETH" K3S_TOKEN=$TOKEN K3S_URL=https://$MASTER_IP:6443 sh - 11 | 12 | echo "done" -------------------------------------------------------------------------------- /init/init_master.sh: -------------------------------------------------------------------------------- 1 | echo "Install K3s Control Plane" 2 | 3 | MASTER_IP=`getent hosts master|grep '192' |awk '{print $1}'` 4 | ETH="enp0s8" 5 | echo "Master IP : "$MASTER_IP 6 | echo "Flannel eth : "$ETH 7 | 8 | curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--bind-address=$MASTER_IP --node-external-ip=$MASTER_IP --flannel-iface=$ETH" sh - 9 | 10 | mkdir -p /vagrant/tmp 11 | cp /var/lib/rancher/k3s/server/node-token /vagrant/tmp/node-token 12 | cp /etc/rancher/k3s/k3s.yaml /vagrant/tmp/k3s.yaml 13 | 14 | sed -i "s/127.0.0.1/$MASTER_IP/g" /vagrant/tmp/k3s.yaml 15 | 16 | echo "done" 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # k3s_vagrant 2 | 3 | This project povides a simple developpment Kubernetes environnement based on K3s and Vagrant. 4 | 5 | 6 | ## Motivation 7 | 8 | Sometimes it is usefull to have a Kub enviomment runing localy on Vitual Machine to play with network configuration and deploiment strategie. So I build with litle simple Vangrant env. 9 | 10 | ## Build the cluster 11 | - Install vagrant and a VMprovider (virtual box) 12 | 13 | - Install vagrant hostmaanger plugin : 14 | ``` vagrant plugin install vagrant-hostmanager ``` 15 | 16 | - Edit the vagrant file to matchi your VM provider internal network 17 | 18 | - Start vagrant 19 | ``` vagrant up ``` 20 | 21 | - Copy information from tmp/k3s.yml in your kube config and run any kubctl command. 22 | 23 | 24 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | 2 | # -*- mode: ruby -*- 3 | # vi: set ft=ruby : 4 | ENV['VAGRANT_NO_PARALLEL'] = 'yes' 5 | Vagrant.configure("2") do |config| 6 | cpu_worker = 2 7 | mem_worker = 2048 8 | base_ip_str = "192.168.56.10" 9 | config.vm.box = "ubuntu/jammy64" 10 | config.hostmanager.enabled = true 11 | config.hostmanager.manage_host = true 12 | 13 | config.vm.define "master" do |confVB| 14 | confVB.vm.hostname = "master" 15 | # Give it a fixed IP 16 | confVB.vm.network "private_network", ip: "#{base_ip_str}1", :netmask => "255.255.255.0" 17 | confVB.vm.provider "virtualbox" do |v| 18 | v.memory = mem_worker 19 | v.cpus = cpu_worker 20 | end 21 | confVB.vm.provision "shell", path: "init/init_master.sh" 22 | end 23 | 24 | config.vm.define "worker1" do |confVB| 25 | confVB.vm.hostname = "worker1" 26 | # Give it a fixed IP 27 | confVB.vm.network "private_network", ip: "#{base_ip_str}2", :netmask => "255.255.255.0" 28 | confVB.vm.provider "virtualbox" do |v| 29 | v.memory = mem_worker 30 | v.cpus = cpu_worker 31 | end 32 | confVB.vm.provision "shell", path: "init/init_worker.sh" 33 | end 34 | 35 | # config.vm.define "worker2" do |confVB| 36 | # confVB.vm.hostname = "worker2" 37 | # # Give it a fixed IP 38 | # confVB.vm.network "private_network", ip: "#{base_ip_str}3", :netmask => "255.255.255.0" 39 | # confVB.vm.provider "virtualbox" do |v| 40 | # v.memory = mem_worker 41 | # v.cpus = cpu_worker 42 | # end 43 | # confVB.vm.provision "shell", path: "init/init_worker.sh" 44 | # end 45 | 46 | end 47 | --------------------------------------------------------------------------------