LXD

インストール

$ sudo snap install lxd
lxd (5.21/stable) 5.21.2-084c8c8 from Canonical✓ installed

$ sudo lxd init
全てデフォルト

【備忘録】

loop device容量: 30GiB
ローカルネットワークブリッジ: 作ります
ブリッジの名前: lxdbr0
IPv4: auto
IPv6: auto

プロファイル作成

$ lxc profile create myProfile
$ wget https://raw.githubusercontent.com/ubuntu/microk8s/master/tests/lxc/microk8s-zfs.profile -O microk8s.profile
$ cat microk8s.profile | lxc profile edit myProfile
$ rm microk8s.profile

masterノード作成

$ lxc launch -p default -p myProfile ubuntu:24.04 master
Creating master
Starting master
$ lxc exec master -- sudo snap install microk8s --classic
$ lxc exec master -- sudo snap alias microk8s.kubectl kubectl

AppArmor profiles

$ 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
$ lxc list master

workerノード用のイメージを保存する

workerノードのイメージはmasterノードのイメージと基本一緒なので、ひな形を作成しておく。

$ lxc stop master
$ lxc publish master --alias myProfile
$ lxc start master
$ sudo lxc image edit myProfile

最後に追記
– myProfile

workerノード作成

$ lxc launch myProfile worker01
$ lxc launch myProfile worker02

ノード追加

マスターノードでmicrok8s add-node。
表示されたmicrok8s join … を、ワーカーノードで貼り付け。

worker01

$ 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

$ lxc shell worker01
# microk8s join 10.12.160.6:25000/7e79e070bd9169f57b8e5c9cc108286f/9b795b17b8e6 --worker
# exit

worker02

$ 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

$ lxc shell worker02
# 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

確認

$ lxc exec master -- kubectl get nodes -o wide
NAME       STATUS   ROLES    AGE     VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
worker01   Ready    <none>   15m     v1.27.5   10.12.160.238   <none>        Ubuntu 20.04.6 LTS   6.2.0-33-generic   containerd://1.6.15
master     Ready    <none>   40m     v1.27.5   10.12.160.6     <none>        Ubuntu 20.04.6 LTS   6.2.0-33-generic   containerd://1.6.15
worker02   Ready    <none>   7m6s    v1.27.5   10.12.160.100   <none>        Ubuntu 20.04.6 LTS   6.2.0-33-generic   containerd://1.6.15
タイトルとURLをコピーしました