I run a pretty much out-of-the-box default LXD setup.
I quite literally accepted almost all of the defaults during lxd init phase.
That means, among other things, that networking is managed by LXD + dnsmasq.
This is quite useful in my case but I also need most of my containers to have static IP addresses.
Apparently, there are several ways to do it and I’m wondering if any particular method is preferred or advised as a best practice.
E.g. I tried installing ifupdown in one of the containers and configured network interfaces with static IP addresses as well as static routes.
I also, attached an eth0 device to another container, assigned IP address to that container and that worked as well. Networking in that container itself is basically configured via default netplan configuration that requests all the parameters from a DHCP server. So, my understanding is that ipv4.address assigned to the attached eth0 device acts kind of like a static DHCP lease (please, correct me if I’m wrong).
There’s also a macvlan approach, which I haven’t tried yet.
So, is any particular method better or preferred for some reason?
As far as I can see, we are free to mix and match as we find convenient. But is it a good idea? What is regarded as the best practice?
Again, for me having LXD manage container networking is beneficial as it allows for quick and easy creation of containers that are ready for use and can reach the Internet.
If I need any container to have a static IP address without having to actually configure anything in the container I can do this via lxc network attach + lxc config device commands. Which is also scriptable and allows for easy, rapid and massive deployments by using some sort of orchestration tool.
Then, I found that configuring more complex networking (several IP addresses, static routes, SNAT/DNAT iptables rules, etc.) is best achieved inside a container using ifupdown.
So, what I’m saying is that in my particular LXD setup all three methods are quite useful.
The question is, is it an optimal approach or is there even a better/more elegant way?