Demo environment with LXD local domain setup - ghomem/legacy_puppet_infrastructure GitHub Wiki
LXD comes pre-installed by default in Ubuntu Server, in case you want to install it in your laptop you can install it with:
sudo snap install lxd --channel=5.0/stable
Once installed you can proceed to initialize the LXD configutaion with:
sudo lxd init
Let's say we want to create a couple of containers using a local domain named puppetdemo.lan
:
- puppet.puppetdemo.lan
- node01.puppetdemo.lan
First of all, we can set up the domain for lxdbr0
(the default network interface for LXD) with:
sudo lxc network set lxdbr0 dns.domain=puppetdemo.lan
Now we create the containers with:
sudo lxc launch ubuntu:22.04 puppet
sudo lxc launch ubuntu:22.04 node01
Now we should be able to use the *.puppetdemo.lan inside the LXD network, but not outside:
user@laptop:~$ sudo lxc exec node01 bash
root@node01:~# ping puppet.puppetdemo.lan
PING puppet.puppetdemo.lan (10.103.21.215) 56(84) bytes of data.
64 bytes from puppet.puppetdemo.lan (10.103.21.215): icmp_seq=1 ttl=64 time=0.084 ms
64 bytes from puppet.puppetdemo.lan (10.103.21.215): icmp_seq=2 ttl=64 time=0.059 ms
64 bytes from puppet.puppetdemo.lan (10.103.21.215): icmp_seq=3 ttl=64 time=0.062 ms
64 bytes from puppet.puppetdemo.lan (10.103.21.215): icmp_seq=4 ttl=64 time=0.141 ms
^C
--- puppet.puppetdemo.lan ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3050ms
rtt min/avg/max/mdev = 0.059/0.086/0.141/0.032 ms
root@node01:~# exit
exit
user@laptop:~$ sudo lxc exec puppet bash
root@puppet:~# ping node01.puppetdemo.lan
PING node01.puppetdemo.lan (10.103.21.49) 56(84) bytes of data.
64 bytes from node01.puppetdemo.lan (10.103.21.49): icmp_seq=1 ttl=64 time=0.109 ms
64 bytes from node01.puppetdemo.lan (10.103.21.49): icmp_seq=2 ttl=64 time=0.126 ms
64 bytes from node01.puppetdemo.lan (10.103.21.49): icmp_seq=3 ttl=64 time=0.076 ms
64 bytes from node01.puppetdemo.lan (10.103.21.49): icmp_seq=4 ttl=64 time=0.061 ms
^C
--- node01.puppetdemo.lan ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3025ms
rtt min/avg/max/mdev = 0.061/0.093/0.126/0.025 ms
root@puppet:~# exit
exit
user@laptop:~$ host puppet.puppetdemo.lan
Host puppet.puppetdemo.lan not found: 3(NXDOMAIN)
user@laptop:~$ host node01.puppetdemo.lan
Host node01.puppetdemo.lan not found: 3(NXDOMAIN)
We will see how to fix this in the next section.
We can just edit the /etc/hosts of the LXD server, so we can access the containers by name, example:
user@laptop:~$ sudo lxc list
+--------------------+---------+----------------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------------------+---------+----------------------+------+-----------+-----------+
| node01 | RUNNING | 10.103.21.49 (eth0) | | CONTAINER | 0 |
+--------------------+---------+----------------------+------+-----------+-----------+
| puppet | RUNNING | 10.103.21.215 (eth0) | | CONTAINER | 0 |
+--------------------+---------+----------------------+------+-----------+-----------+
user@laptop:~$ cat /etc/hosts
...
# Puppet demo
10.103.21.49 node01.puppetdemo.lan
10.103.21.215 puppet.puppetdemo.lan
user@laptop:~$ ping node01.puppetdemo.lan
PING node01.puppetdemo.lan (10.103.21.49) 56(84) bytes of data.
64 bytes from node01.puppetdemo.lan (10.103.21.49): icmp_seq=1 ttl=64 time=0.139 ms
64 bytes from node01.puppetdemo.lan (10.103.21.49): icmp_seq=2 ttl=64 time=0.120 ms
64 bytes from node01.puppetdemo.lan (10.103.21.49): icmp_seq=3 ttl=64 time=0.115 ms
64 bytes from node01.puppetdemo.lan (10.103.21.49): icmp_seq=4 ttl=64 time=0.172 ms
^C
--- node01.puppetdemo.lan ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3079ms
rtt min/avg/max/mdev = 0.115/0.136/0.172/0.022 ms
user@laptop:~$ ping puppet.puppetdemo.lan
PING puppet.puppetdemo.lan (10.103.21.215) 56(84) bytes of data.
64 bytes from puppet.puppetdemo.lan (10.103.21.215): icmp_seq=1 ttl=64 time=0.136 ms
64 bytes from puppet.puppetdemo.lan (10.103.21.215): icmp_seq=2 ttl=64 time=0.131 ms
64 bytes from puppet.puppetdemo.lan (10.103.21.215): icmp_seq=3 ttl=64 time=0.116 ms
64 bytes from puppet.puppetdemo.lan (10.103.21.215): icmp_seq=4 ttl=64 time=0.150 ms
^C
--- puppet.puppetdemo.lan ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3062ms
rtt min/avg/max/mdev = 0.116/0.133/0.150/0.012 ms
Editing /etc/hosts
might be a bit inconvenient, so if you are using your laptop and it's configured to use Network Manager, there is a better alternative.
LXD comes with a DNS server; this server listens on the IP address of the lxdbr0
interface, sop first of all we have to find out the IP of the lxbbr0 interface:
$ ip a show dev lxdbr0
7: lxdbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 00:16:3e:b9:36:d1 brd ff:ff:ff:ff:ff:ff
inet 10.103.21.1/24 scope global lxdbr0
valid_lft forever preferred_lft forever
As we can see, in this case it's 10.103.21.1
. Now, if we don't have it already, we have to add the dns=dnsmasq
in the [main]
section of /etc/NetworkManager/NetworkManager.conf
, example:
$ cat /etc/NetworkManager/NetworkManager.conf
[main]
dns=dnsmasq
plugins=ifupdown,keyfile
[ifupdown]
managed=false
[device]
wifi.scan-rand-mac-address=no
Once that's done, we have to alter the way dnsmasq is executed by Network Manager, to use as DNS server the lxdbr0
IP address to resolve the *.puppetdemo.lan host names. We can do this by creating a new file in /etc/NetworkManager/dnsmasq.d/
, example:
$ cat /etc/NetworkManager/dnsmasq.d/00-puppetdemo.conf
server=/puppetdemo.lan/10.103.21.1
Replace above 10.103.21.1
with the actual IP of your lxdbr0
interface.