MicroK8s - MicroK8s in LXD | MicroK8s
MicroK8s is the simplest production-grade upstream K8s. Ligh...
インストール
$ sudo snap install lxd
lxd (5.21/stable) 5.21.3-75def3c from Canonical✓ installed
$ sudo lxd init
全てデフォルト
【備忘録】
loop device容量: 30GiB
ローカルネットワークブリッジ: 作ります
ブリッジの名前: lxdbr0
IPv4: auto
IPv6: auto
プロファイル作成
$ sudo lxc profile create myProfile
$ wget https://raw.githubusercontent.com/ubuntu/microk8s/master/tests/lxc/microk8s-zfs.profile -O microk8s.profile
$ cat microk8s.profile | sudo lxc profile edit myProfile
$ rm microk8s.profile
masterノード作成
$ sudo lxc launch -p default -p myProfile ubuntu:24.04 master
$ sudo lxc exec master -- sudo snap install microk8s --classic
$ sudo lxc exec master -- sudo snap alias microk8s.kubectl kubectl
AppArmor profiles
$ sudo lxc shell master
$ cat > /etc/rc.local <<EOF
#!/bin/bash
apparmor_parser --replace /var/lib/snapd/apparmor/profiles/snap.microk8s.*
exit 0
EOF
# chmod +x /etc/rc.local
# exit
$ sudo lxc list master

workerノード用のイメージを保存する
workerノードのイメージはmasterノードのイメージと基本一緒なので、ひな形を作成しておく。
$ sudo lxc stop master
$ sudo lxc publish master --alias myProfile
$ sudo lxc start master
$ sudo lxc image edit myProfile
最後に追記
– myProfile
workerノード作成
$ sudo lxc launch myProfile worker-1
$ sudo lxc launch myProfile worker-2
ノード追加
マスターノードでmicrok8s add-node。
表示されたmicrok8s join … を、ワーカーノードで貼り付け。
worker-1
$ sudo lxc exec master -- microk8s add-node
From the node you wish to join to this cluster, run the following:
microk8s join 10.12.160.6:25000/7e79e070bd9169f57b8e5c9cc108286f/9b795b17b8e6
Use the '--worker' flag to join a node as a worker not running the control plane, eg:
microk8s join 10.12.160.6:25000/7e79e070bd9169f57b8e5c9cc108286f/9b795b17b8e6 --worker
If the node you are adding is not reachable through the default interface you can use one of the following:
microk8s join 10.12.160.6:25000/7e79e070bd9169f57b8e5c9cc108286f/9b795b17b8e6
microk8s join fd42:abfe:1775:df51:216:3eff:fe30:2c47:25000/7e79e070bd9169f57b8e5c9cc108286f/9b795b17b8e6
$ sudo lxc shell worker-1
# microk8s join 10.12.160.6:25000/7e79e070bd9169f57b8e5c9cc108286f/9b795b17b8e6 --worker
# exit
worker-2
$ sudo lxc exec master -- microk8s add-node
From the node you wish to join to this cluster, run the following:
microk8s join 10.12.160.6:25000/c2fd470dcf7ee8c6fe93ea73acc5eb56/9b795b17b8e6
Use the '--worker' flag to join a node as a worker not running the control plane, eg:
microk8s join 10.12.160.6:25000/c2fd470dcf7ee8c6fe93ea73acc5eb56/9b795b17b8e6 --worker
If the node you are adding is not reachable through the default interface you can use one of the following:
microk8s join 10.12.160.6:25000/c2fd470dcf7ee8c6fe93ea73acc5eb56/9b795b17b8e6
microk8s join fd42:abfe:1775:df51:216:3eff:fe30:2c47:25000/c2fd470dcf7ee8c6fe93ea73acc5eb56/9b795b17b8e6
$ sudo lxc shell worker-2
# microk8s join 10.12.160.6:25000/c2fd470dcf7ee8c6fe93ea73acc5eb56/9b795b17b8e6 --worker
# exit
正常終了コメント
The node has joined the cluster and will appear in the nodes list in a few seconds.
This worker node gets automatically configured with the API server endpoints.
If the API servers are behind a loadbalancer please set the '--refresh-interval' to '0s' in:
/var/snap/microk8s/current/args/apiserver-proxy
and replace the API server endpoints with the one provided by the loadbalancer in:
/var/snap/microk8s/current/args/traefik/provider.yaml
確認
$ sudo lxc exec master -- kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
master Ready <none> 26m v1.32.1 10.218.43.61 <none> Ubuntu 24.04.2 LTS 6.11.0-17-generic containerd://1.6.36
worker-1 Ready <none> 2m3s v1.32.1 10.218.43.231 <none> Ubuntu 24.04.2 LTS 6.11.0-17-generic containerd://1.6.36
worker-2 Ready <none> 21s v1.32.1 10.218.43.162 <none> Ubuntu 24.04.2 LTS 6.11.0-17-generic containerd://1.6.36