Obvious questions about cloud-init
Posted by lightnb11@reddit | linuxadmin | View on Reddit | 10 comments
There are pages and pages of documentation that fail to answer the most obvious questions that someone who has never used cloud-init before would have about it:
The docs say:
During boot, cloud-init identifies the cloud it is running on and initialises the system accordingly.
(1) What is booting, the new VM?
(2) Where does cloud-init run? Inside the newly created VM? On the host? On a "cloud-init server" in the data center?
(3) Is cloud-init an executable? That runs inside the vm?
(4) How does it "identif[y] the cloud it is running on"? DNS?
(5) "initialises the system accordingly"... according to what? Where does your configuration file go? On the host? Inside the vm?
(6) How does cloud-init get installed inside the vm?
(7) Does cloud-init require something external to the vm, like a "cloud-init server" that's in the data center?
OK. So let's say I have a bare metal machine with KVM/Libvirt on it. I use virt-install
to make new virtual machines. How do I make cloud-init
put my ssh public key on new virtual machines?
neo-B@reddit
I would recommend working through the official tutorial[1]. It answers these questions.
[1] https://cloudinit.readthedocs.io/en/latest/tutorial/qemu.html
ForceBlade@reddit
Yes.
It is software that runs on just about any Linux distribution. When your distribution of choice boots, it is a generic instance which instantly launches cloud-init.
Yes. It's just python.
lspci
will give away the virtualization platform 99.9% of the time. Otherwise yes there are other ways to figure out what provider you are running on.According to the cloud-init data you tell it to initialize with. Like how Ansible or Saltstack function - it takes a YAML-formatted cloud-init file which tells the system exactly what you want.
Your brand new VM boots an image your provider prepared earlier which invokes cloud-init if asked to. On Linux it's just a package like any other.
It's an option. Most VPS providers just let you paste in cloud-init data. Even if that just tells it to reach out to some provisioning server.
ImpossibleEdge4961@reddit
Might be worth linking this page
ImpossibleEdge4961@reddit
Also worth bringing up things like fwcfg which is also a source of truth used by cloud-init
lightnb11@reddit (OP)
Is cloud-init something that's pretty much guaranteed to come preinstalled with any bare-bones Linux distribution, even if it's not a cloud provider's image? For example, OpenSSH and BASH will always be included with any distro.
Where does this data come from? Do you put the YAML file into a custom image for the VM? And if so, what is the point of a custom YAML file on the vm image? Because if you have to create a custom image anyway, why not just put the files you want where you want them and bake them into the image?
One foundational question I have is: Will cloud-init be useful to me at all if I don't make my own Linux images?
ghjm@reddit
Most hypervisors and cloud providers allow you to add a text block to the VM configuration. This is the most common way to pass in instance-specific data. For bare metal servers you either supply information in a DHCP response, or have a configuration server like Foreman, usually keyed off the MAC address of the host being provisioned.
agent-squirrel@reddit
Another option is to use a "cloud-init drive" like Proxmox does.
cyril1991@reddit
Not completely sure as I am not an expert on it, but cloud-init runs on anything including your regular Ubuntu installation on your own computer (datasource “nocloud”). The operating system is booting, it can be a VM or not, and it runs in that OS to set up things like networking, hostname etc… Cloud-init is an executable already present in your OS/VM, but it is just a regular package that can be updated. It can infer some information on where it is being run, but the interest is that you can use a config file. I don’t know if you can use a server to get some config values, but crucially cloud-init is often used to set up networking and DNS.
It solves the chicken-and-egg problem of how to configure a computer or vm while it boots, where you may need to access the network but it has not been configured. You have an industry standard configuration file and executable, instead of a bunch of scripts that may break down. You can just pack a config file in an ISO and get going.
Some docs is at https://cloudinit.readthedocs.io/en/latest/explanation/introduction.html
lightnb11@reddit (OP)
That last link seems very good. I've only started reading it, but it has already explained cloud-init better than the official docs!
TheBlueKingLP@reddit
Cloud init usually used by system administrators or data center automation tools. 1. The VM 2. It runs inside the VM, usually pre-installed with a "cloud vm image".
3. It is a packaged including executable.
4. The VM hypervisor passes a special disk to the VM and cloud init reads a config from that special disk.
5. Same as above.
6. It usually comes with the cloud image pre installed by the image builder.
7. No. It only requires the cloud init virtual disk attached to the VM