## 目的
lxdcliにlxdクラスタを構築する機能が追加された。今回はその方法を忘れない様に備忘録を残しておく。
ファイル
- lxdfile
- lxdclusterfile
- lxdconfig-master
- lxdconfig-worker
手順
- lxdcliのインストール
- クラスタ用のノードを用意
- cluster定義ファイルの作成
- master用の設定ファイルの作成
- worker用の設定ファイルの作成
- クラスタの作成
lxdcliのインストール
lxdcliは、lxdのラッパーツールである。そのため、まずはlxdをインストールしないといけない。
snapのインストール
apt -y install snapd
lxdのインストール
snap install lxd
lxdの設定
lxd init --auto
lxdcliのインストール
git clone https://github.com/shoma564/lxdcli.git
cd lxdcli
install lxdcli /usr/local/sbin/
pip install pylxd
クラスタ用のノードを用意
以下のファイルを用意する。
lxdfile
CONTAINERNAME ubuntu-lxd
FROM ubuntu/22.04
RUN export DEBIAN_FRONTEND=noninteractive
#RUN timedatectl set-timezone Asia/Tokyo && hostnamectl set-hostname ubuntu-base
RUN apt-get -y update
RUN dpkg --configure -a
RUN echo "\n\n\n" | apt-get -y install openssh-server
RUN echo -e "root:password" | chpasswd
RUN echo -e 'PermitRootLogin yes' >> /etc/ssh/sshd_config
RUN systemctl enable ssh
RUN systemctl restart ssh
RUN systemctl start ssh
RUN apt -y install nano snapd
RUN snap install lxd
NUMBER 3
ビルドする
lxdcli build lxdfile
ノードが出来上がった。
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-lxd | RUNNING | 10.85.165.6 (eth0) | fd42:d04c:aa87:84fb:216:3eff:fee2:7eaf (eth0) | CONTAINER | 0 |
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-lxd-0 | RUNNING | 10.85.165.50 (eth0) | fd42:d04c:aa87:84fb:216:3eff:fe37:c025 (eth0) | CONTAINER | 0 |
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-lxd-1 | RUNNING | 10.85.165.223 (eth0) | fd42:d04c:aa87:84fb:216:3eff:fea8:f589 (eth0) | CONTAINER | 0 |
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-lxd-2 | RUNNING | 10.85.165.27 (eth0) | fd42:d04c:aa87:84fb:216:3eff:fe7a:dfd6 (eth0) | CONTAINER | 0 |
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
cluster定義ファイルの作成
clusterの定義ファイルを作成する。
ubuntu-lxd 10.85.165.6 root password
ubuntu-lxd-0 10.85.165.50 root password
ubuntu-lxd-1 10.85.165.223 root password
ubuntu-lxd-2 10.85.165.27 root password
一番上に記述したノードがmasterノードとなる。
- master用の設定ファイルの作成
lxdconfig-master
yes
- worker用の設定ファイルの作成
lxdconfig-worker
yes
yes
yes
token_here
yes
- クラスタの作成
全てのファイルが揃ったのでクラスタを作成していく。
$ lxdcli cluster
確認
root@shoma:/home/shoma/lxdcluster# lxc list
+--------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-lxd | RUNNING | 240.6.0.1 (lxdfan0) | fd42:d04c:aa87:84fb:216:3eff:fee2:7eaf (eth0) | CONTAINER | 0 |
| | | 10.85.165.6 (eth0) | | | |
+--------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-lxd-0 | RUNNING | 240.50.0.1 (lxdfan0) | fd42:d04c:aa87:84fb:216:3eff:fe37:c025 (eth0) | CONTAINER | 0 |
| | | 10.85.165.50 (eth0) | | | |
+--------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-lxd-1 | RUNNING | 240.223.0.1 (lxdfan0) | fd42:d04c:aa87:84fb:216:3eff:fea8:f589 (eth0) | CONTAINER | 0 |
| | | 10.85.165.223 (eth0) | | | |
+--------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-lxd-2 | RUNNING | 240.27.0.1 (lxdfan0) | fd42:d04c:aa87:84fb:216:3eff:fe7a:dfd6 (eth0) | CONTAINER | 0 |
| | | 10.85.165.27 (eth0) | | | |
+--------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+