tabimoba.net

とあるエンジニアの雑記帳

パブリックなLXDイメージリポジトリの構築と、構築したパブリックLXDイメージリポジトリからのイメージ取得

LXDイメージリポジトリの構築

LXDイメージリポジトリとするサーバ(LXDイメージリポジトリサーバ)で設定を行います。

# lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: no
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes
Name of the new storage pool [default=default]: default
Name of the storage backend to use (btrfs, dir, lvm) [default=btrfs]: dir
Would you like to connect to a MAAS server? (yes/no) [default=no]: no
Would you like to create a new local network bridge? (yes/no) [default=yes]: yes
What should the new bridge be called? [default=lxdbr0]: lxdbr0
What IPv4 address should be used? (CIDR subnet notation, auto or none) [default=auto]: auto
Would you like LXD to NAT IPv4 traffic on your bridge? [default=yes]: yes
What IPv6 address should be used? (CIDR subnet notation, auto or none) [default=auto]: none
Would you like LXD to be available over the network? (yes/no) [default=no]: yes
Address to bind LXD to (not including port) [default=all]: all
Port to bind LXD to [default=8443]: 8443
Trust password for new clients:  <パスワードを入力>
Again: <パスワードを入力>
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] : yes
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: no

LXDイメージリポジトリへのイメージ追加(パブリッシュ)

LXDイメージリポジトリサーバで行う場合

# lxc publish <LXDコンテナ名> --public --alias <LXDコンテナイメージ名>

LXDイメージリポジトリサーバとは別のサーバ等で行う場合

# lxc publish <LXDコンテナ名> <LXDイメージリポジトリサーバ>: --public --alias <LXDコンテナイメージ名>

なお、イメージ追加を行うサーバ等においては、事前にLXDリポジトリサーバと相互に接続可能な状態とする必要があります。追加されていない場合は、以下のコマンドでLXDイメージリポジトリを追加します。

# lxc config set core.https_address "[::]:8443"
# lxc remote add https://<LXDイメージリポジトリサーバのIPアドレスまたはURL>:<ポート(デフォルト:8443)>

パブリックLXDイメージリポジトリの追加

LXDイメージリポジトリサーバ上のイメージを利用したいサーバ等より操作を行います。

# lxc config set core.https_address "[::]:8443"
# lxc remote add https://<LXDイメージリポジトリサーバのIPアドレスまたはURL>:<ポート(デフォルト:8443)> --public

パブリックLXDイメージリポジトリの利用

LXDイメージリポジトリサーバ上のイメージを利用したいサーバ等より操作を行います。

イメージ一覧の取得

# lxc image list <LXDイメージリポジトリサーバ>:

イメージを使用してコンテナを起動

# lxc launch <LXDイメージリポジトリサーバ>:<LXDコンテナイメージ名> --alias <LXDコンテナ名(エイリアス)>