MicroK8s Installation
These steps need to be repeated for each container on the host
Installation
This command installs and launches an empty OS Ubuntu 22.04 inside a container named homekube
and applies 3 profiles in the order of specification. Later profile specs override earlier specs
so we can be sure that our macvlan network settings are honored:
lxc launch -p default -p microk8s -p macvlan ubuntu:22.04 homekube
Lets check if we were successful lxc list
results in something like
+----------+---------+----------------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+----------+---------+----------------------+------+-----------+-----------+
| homekube | RUNNING | 192.168.1.101 (eth0) | | CONTAINER | 0 |
+----------+---------+----------------------+------+-----------+-----------+
Note the IP V4 indicates that the container got an IP from DHCP service of our local network. But always keep in mind that this container will not be reachable from the host. Thats the limitation of macvlan networks. In case thats too limiting for you you need to install a bridge. Read more about bridge configuration here
Now we install microk8s
inside a container named homekube
and give it access to our cloned homekube repository on the host.
cd ~/homekube # your fork of https://github.com/homekube/homekube.git
lxc config device add homekube homekube disk source=$(pwd) path=/root/homekube
lxc exec homekube -- snap install microk8s --classic --channel=1.25/stable
lxc exec homekube -- microk8s status --wait-ready
lxc exec homekube -- microk8s enable dns rbac helm3
Execute lxc list
again and you should see something like
+----------+---------+----------------------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+----------+---------+----------------------------+------+-----------+-----------+
| homekube | RUNNING | 192.168.1.101 (eth0) | | CONTAINER | 0 |
| | | 10.1.74.128 (vxlan.calico) | | | |
+----------+---------+----------------------------+------+-----------+-----------+
Fix AppArmor settings
These fixes are needed for the container to survive a reboot. When the LXD container boots it needs to load the AppArmor profiles required by MicroK8s or else you may get the error:
cannot change profile for the next exec call: No such file or directory
Now step into the fresh container
lxc exec homekube -- bash
and execute the next commands from inside the container
cat > /etc/rc.local <<EOF
#!/bin/bash
apparmor_parser --replace /var/lib/snapd/apparmor/profiles/snap.microk8s.*
exit 0
EOF
Make the rc.local executable:
chmod +x /etc/rc.local
Fine tuning
On order to make all our existing scripts working out of the box we need to apply the following changes once in the container:
Add aliases for kubectl
and helm
cat >> .bash_aliases << EOF
alias kubectl='microk8s kubectl'
alias helm='microk8s helm3'
EOF
Reboot and enjoy
exit
the container and restart lxc restart homekube
it to activate the changes.
Reenter the container lxc exec homekube -- bash
and verify the installation:
kubectl version --short
Client Version: v1.25.4
Kustomize Version: v4.5.7
Server Version: v1.25.4
Now We are done with installation in a Microk8s container
Install Homekube appliances
TLDR; Install all Homekube appliances in one go
lxc exec homekube -- bash
cd ~/homekube/src
# NOTE! edit env variables in install-all.sh to match your installation
bash -i install-all.sh
Learn the individual steps and take the quick tour
Now proceed with the individual steps by taking the Quick tour
Further reading
Recommendations about using lxd
Troubleshooting
Error: cannot change profile for the next exec call: No such file or directory