Guide
Install Kubernetes in LXD
Setup notes for Kubernetes and containerd in LXD.
On this page
LXD setup
pacman -S lxd lxc
LXC configuration
# /etc/lxc/default.conf
lxc.net.0.type = empty
lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536
# This is for kmsg in container
lxc.kmsg = 1
Start LXD
sudo systemctl enable --now lxd.service
lxd init
Kubernetes profile
lxc profile copy default k8s
lxc profile edit k8s
LXD profile for kubernetes, from Microk8s
config:
limits.cpu: "2"
limits.memory: 2GB
limits.memory.swap: "false"
linux.kernel_modules: ip_vs,ip_vs_rr,ip_vs_wrr,ip_vs_sh,ip_tables,ip6_tables,netlink_diag,nf_nat,overlay,br_netfilter
raw.lxc: |
lxc.apparmor.profile=unconfined
lxc.mount.auto=proc:rw sys:rw
lxc.cgroup.devices.allow=a
lxc.cap.drop=
security.nesting: "true"
security.privileged: "true"
user.user-data: |
#cloud-config
ssh_authorized_keys:
- @@SSH_KEY@@
description: Kubernetes LXD profile
devices:
eth0:
name: eth0
network: lxdbr0
type: nic
root:
path: /
pool: @@Storage@@
type: disk
name: k8s
Install containerd
sudo apt update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install containerd.io
Override unit file to not execute modprobe overlay
sudo systemctl edit containerd.service
Add this
[Service]
ExecStartPre=
Write the default configuration for containerd into the config file.
containerd config default > /etc/containerd/config.toml
sudo systemctl restart containerd
In case /dev/kmsg is not there in the container, you can symlink /dev/console to it.
ln -sf /dev/console /dev/kmsg
Install Kubeadm, kubectl and kubelet in master nodes
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
With btrfs storage backends, the kubelet encounters many problems during startup. To work around this, we need to state the kubelet configuration manually during kubeadm init.
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
featureGates:
LocalStorageCapacityIsolation: false