LoginSignup
3
3

More than 3 years have passed since last update.

Ubuntu18.04でLXDとコンテナ用DNSの設定

Last updated at Posted at 2019-04-23

環境

  • Ubuntu18.04

Server 設定

事前に最低限 update & upgrade はやりましょう

apt-get update
apt-get upgrade

/etc/sysctl.conf

user.max_user_namespaces = 3883
fs.inotify.max_queued_events = 1048576
fs.inotify.max_user_instances = 1048576
fs.inotify.max_user_watches = 1048576
vm.max_map_count = 262144
net.ipv4.ip_forward = 1

/etc/security/limits.conf

*               soft    nofile          1048576
*               hard    nofile          1048576
root            soft    nofile          1048576
root            hard    nofile          1048576
*               soft    memlock         unlimited
*               hard    memlock         unlimited

一旦再起動するのが無難です

reboot

設定内容の詳細は以下を確認してください。
https://github.com/lxc/lxd/blob/master/doc/production-setup.md

LXD 初期設定

今回はサクッと設定するので silent install

lxd init --auto

Container 作成、login、update


# container 作成
lxc launch ubuntu:18.04 container01
# container login
lxc exec container01 /bin/bash

# 以下は container 内でのcommandです
vi  /etc/systemd/resolved.conf
+DNS = 127.0.0.53 8.8.8.8
:wq
systemctl restart systemd-resolved
apt-get update
apt-get upgrade

# container から抜ける
exit

ホスト側Ubuntu内からcontainer名.lxd でアクセスできるようにする

以下のURLの内容そのままですが...
参考:https://blog.simos.info/how-to-use-lxd-container-hostnames-on-the-host-in-ubuntu-18-04/

lxd-br0.sh 作成
#!bin/bash

set -eu

LXDBRIP="$(ip addr show dev lxdbr0| grep -Po 'inet \K[\d.]+')"
sudo systemd-resolve --interface lxdbr0 --set-dns ${LXDBRIP} --set-domain lxd
echo -e "auth-zone=lxd\ndns-loop-detect" | lxc network set lxdbr0 raw.dnsmasq -
lxc network show lxdbr0
echo "All done.. try command"
echo "dig [container_name].lxd @${LXDBRIP}"
実行
bash -x lxd-br0.sh
dig 確認
; <<>> DiG 9.11.3-1ubuntu1.5-Ubuntu <<>> container01.lxd +noall +answer
;; global options: +cmd
container01.lxd.        600     IN      A       10.127.173.47
PING 確認
root@ubuntu-bionic:~# ping -c 1 container01.lxd
PING container01.lxd(container01.lxd (fd42:b79:f367:b587:216:3eff:fe6f:a54c)) 56 data bytes
64 bytes from container01.lxd (fd42:b79:f367:b587:216:3eff:fe6f:a54c): icmp_seq=1 ttl=64 time=0.058 ms

DNSのサービス化は省略。
Nginx等でProxy等を用意すれば、Container別にアクセスを分けることができます。
SSHのProxyは...鍵認証ができないけれど sshpiper が良いかと。
https://github.com/tg123/sshpiper
※ 2019/05/13 普通に見落としていました。鍵使えるようです。
mekstr様、情報ありがとうございます。
https://github.com/tg123/sshpiper#how-to-do-public-key-authentication-when-using-sshpiper

3
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3