Boot with cloud-init
Last updated
Last updated
Cloud-init is a software package that automates the initialization of servers during system boot. When you deploy a new Linux server from an image, cloud-init gives you the option to set default user data.
User data must be written in shell scripts or cloud-config directives using YAML syntax. You can modify IONOS cloud-init's behavior via user-data. You can pass the user data in various formats to the IONOS cloud-init at launch time. Typically, this happens as a template, a parameter in the CLI, etc. This method is highly compatible across platforms and fully secure.
Compatibility: This service is supported on all public IONOS Cloud Linux distributions. You may submit user data through the DCD or via Cloud API. Existing cloud-init configurations from other providers are compatible with IONOS Cloud.
Limitations: Cloud-init is available on all public Linux images supplied by IONOS Cloud. If you wish to use your own Linux image, please make sure that it is cloud-init supported first. Otherwise, there is no guarantee that the package will function as intended. Windows images are currently out of scope; adding them may be considered at a later stage.
Provisioning: Cloud-init can only be set at initial provisioning. It cannot be applied to instances that have already been provisioned. Settings cannot be changed once provisioned.
Laptops: When using a laptop, scroll down the properties panel of the block storage volume that you want to create and configure, as additional fields are not immediately visible on a small screen. Clout-Init may only become visible when an supported image has been selected.
The following table demonstrates the use of cloud-config and user-data scripts. However, the cloud-init package supports a variety of formats.
Data Format | Description |
---|---|
Log in to the DCD with your username and password.
In the Workspace, create a new virtual instance and attach any storage device to it.
Select the storage device and from the Inspector pane associate an Image with it.
To associate a private image, select Own Images from the drop-down list.
To associate a public image, select IONOS Images from the drop-down list. Once you choose an image, additional fields will appear in the Inspector pane.
Enter a Password. It is required for Remote Console access. You may change it later.
(Optional). Upload a new SSH key or use an existing file. SSH Keys can also be injected as user data utilizing cloud-init.
(Optional). Add a specific key to the Ad-hoc SSH Key field.
Select No configuration for Cloud-Init user data and the Cloud-Init User Data window appears.
Enter your User Data either using a bash script or a cloud-config file with a YAML syntax. For sample scripts, see Use shell scripts, Use cloud-config directives, or Configure user data via API.
To complete setup, return to the Inspector pane and click Provision Changes.
Result: At boot, Cloud-Init executes automatically and applies the specified changes. The DCD returns a message when provisioning is complete, indicating that the infrastructure is virtually ready. However, bootstrapping, which includes the execution of cloud-init data, may require additional time. The message that DCD returns does not mention the additional time required for execution. We recommend allowing extra time for task completion before testing.
Using shell scripts is an easy way to bootstrap a server. The code creates, installs, and configures our CentOS web server in the following example. It also rewrites the default index.html file.
Note: Allow enough time for the instance to launch and run the commands in your script, and later verify if your script has completed the tasks you intended.
To test if the cloud-init bootstrapped your VM successfully, you can open the corresponding IP address in your browser. You will be greeted with a “Hello World” message from your web server.
You can also bootstrap cloud-init images using cloud-config directives. The cloud-init website outlines all the supported modules and provides examples of basic directives.
The cloud-init output log file (/var/log/cloud-init-output.log
) captures console output. Depending on the default configuration for logging, a second log file exists within /var/log/cloud-init.log
. This provides a comprehensive record based on the user data.
The cloud API offers increased convenience if you want to automate the provisioning and configuration of cloud instances. Enter the following details:
Name: Enter the userData.
Type: Enter the type in the form of a string.
Description: The cloud-init configuration for the volume as base64 encoded string. The property is immutable and is only allowed to be set on a new volume creation. It is mandatory to provide either public image
or imageAlias
that has cloud-init compatibility in conjunction with this property.
Cloud-init is configured on the volume resource for cloud API V6 or later versions. For more information, see CLOUD API (6.0).
Base64
If the user data is base64 encoded, cloud-init verifies whether the decoded data is one of the supported types. It decodes and handles the decoded data appropriately if it comprehends it. If not, the base64 data is returned unaltered.
User-Data Script
Begins with #!
or Content-Type: text/x-shellscript
. The script is run by /etc/init.d/cloud-init-user-scripts
during the first boot cycle. This occurs late in the boot process after the initial configuration actions are performed.
Include File
Begins with #include
or Content-Type: text/x-include-url
. The include
file is the content. It contains a collection of URLs, one in each line. Each URL is read, and its content passes through the same set of rules. The content read from the URL can be MIME-multi-part or plaintext.
Cloud Config data
Begins with #cloud-config
or Content-Type: text/cloud-config
. For a commented example of supported configuration formats, see the examples.
Upstart Job
Begins with #upstart-job
or Content-Type: text/upstart-job
. This content is stored within a file in /etc/init
, and upstart uses the content similar to other upstart jobs.
Cloud Boothook
Begins with #cloud-boothook
or Content-Type: text/cloud-boothook
. The boothook
data is the content, which is stored in a file within /var/lib/cloud
and executed immediately. This becomes the earliest hook
and does not have any mechanism for executing it only one time. The must be handled by the boothook itself. It is provided with the instance ID in the environment variable INSTANCE_ID
. Use this variable to provide a once-per-instance set of boothook data.