K3s on a Centos vm
This post is about installing lightweight Kubernetes (K3s) on our new vm.
K3s
The previous post was all about being able to install Kubernetes quickly. For that I will use k3s from Rancher because it is fast. Let's go!
Prepare
We do this for testing so we can safely disable the firewall and SELinux on our CentOS vm. This is because SELinux is still experimental in K3s. We also need to enable ssh password authentication so we can issue scp commands from our host machine. For this we just add the following lines to the extra script part of our Vagrantfile:
1$extra = <<-EXTRA
2dnf update -y && dnf install vim net-tools git lsof tar -y
3sed -i 's/enforcing/disabled/g' /etc/selinux/config
4sed -i 's/PasswordAuthentication\s.*no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
5systemctl disable firewalld
6systemctl restart sshd
7reboot
8EXTRA
9
10Vagrant.configure("2") do |config|
11 config.vm.define "node01" do |node01_config|
12 node01_config.vm.box ="generic/centos8"
13 node01_config.vm.hostname = "centos01"
14 node01_config.vm.provider :libvirt do |domain|
15 domain.memory = 4096
16 domain.cpus = 2
17 domain.nested = true
18 domain.volume_cache = 'none'
19 end
20 end
21 config.vm.provision "shell", inline: $extra
22end
Now log on the the virtual machine and issue these commands:
1curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644
2sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
Now wait a bit. Once ready, you can issue:
1kubectl get pods --all-namespaces
Manage K3s from the host
1 scp vagrant@192.168.122.232:/home/vagrant/.kube/config .
Edit the config and change the 127.0.0.1 address from the server to the ip address of your vm. (Mine is 192.168.122.232)
Then run:
1kubectl get pods --kubeconfig config --all-namespaces
Hooray!