This commit is contained in:
2024-02-20 17:15:27 +08:00
committed by huty
parent 6706e1a633
commit 34158042ad
1529 changed files with 177765 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
# Using Vagrant to run K3s
This configures a virtual machine which installs Docker and K3s.
## Pre-requisites
You need to install [Vagrant](https://www.vagrantup.com) and use one of the supported VM providers:
* Hyper-V on Windows
* VirtualBox on Linux, Windows or Mac
> Pull requests to add support for other providers is welcome :)
## Usage
From this directory run:
```
vagrant up
```
The first time you run this it will take a while to download the base VM, but subsequent runs will be fast.
Connect to the VM:
```
vagrant ssh
```
The VM mounts the `kiamol` folder on your host into the VM, so you can get to all the source for the book from here:
```
cd /kiamol
```
## Teardown
Use one of these options:
* `vagrant suspend` to suspend the VM which keeps your current state
* `vagrant halt` to stop the VM
* `vagrant destroy` to remove the VM altogether

View File

@@ -0,0 +1,26 @@
Vagrant.configure("2") do |config|
config.vm.define "kiamol" do |kiamol|
kiamol.vm.box = "bento/ubuntu-20.04"
kiamol.vm.hostname = "kiamol"
kiamol.vm.network "private_network", type: "dhcp"
kiamol.vm.provision "shell", path: "setup.sh"
kiamol.vm.provision "shell", path: "kiamol.sh", privileged: false
kiamol.vm.synced_folder "../..", "/kiamol"
kiamol.vm.provider :hyperv do |v|
v.vmname = "kiamol"
v.maxmemory = 3000
v.cpus = 2
end
kiamol.vm.provider :virtualbox do |v|
v.name = "kiamol"
v.memory = 3000
v.cpus = 2
end
end
end

View File

@@ -0,0 +1,13 @@
#!/bin/bash
echo '---------'
echo "kiamol.sh as: $(whoami)"
echo '---------'
# set MOTD
sudo sh -c 'echo "\n** Learn Kubernetes in a Month of Lunches **\n** https://kiamol.net **\nSource is in /kiamol\n" > /etc/motd'
# add aliases:
echo "alias k='kubectl'" >> ~/.bashrc
echo "alias d='docker'" >> ~/.bashrc
echo "alias cls='clear'" >> ~/.bashrc

View File

@@ -0,0 +1,27 @@
#!/bin/bash
echo '--------'
echo "setup.sh as: $(whoami)"
echo '--------'
hostname -I | awk '{print $NF}' > /tmp/ip.txt
# turn off swap - for the Kubelet
swapoff -a
sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab
# install Docker
curl -fsSL https://get.docker.com | sh
# use Docker without sudo
sudo usermod -aG docker vagrant
# install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# install Helm
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
# install K3s
curl -sfL https://get.k3s.io | sh -s - --docker --disable=traefik --write-kubeconfig-mode=644