Boot with Cloud-Init
Overview
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.
Supported user data formats
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 |
---|---|
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 |
Include File | Begins with |
Cloud Config data | Begins with |
Upstart Job | Begins with |
Cloud Boothook | Begins with |
Configuring user data via the DCD
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, and 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.
Use shell scripts
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.
Use cloud-config directives
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.
Example 1: Create a swap partition
The following script is an example of how to create a swap partition with second block storage using a YAML script:
Example 2: Resize the file system
The following script is an example of how to resize your file system according to the chosen size of the block storage. It will also create a user with an SSH key using a cloud-config YAML script:
Output log files
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.
Configure user data via API
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
orimageAlias
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).
Curl example
The following script is an example of how to configure userData using curl:
Last updated