Custom settings on nodes
The NodeGroupConfiguration resource is provided to automate actions on group nodes. The resource allows you to run bash scripts on nodes that can use the bashbooster command set, and also allows you to use the Go Template templating engine. This is convenient for automating operations such as:
Installing and configuring additional OS packages.
Example:
Updating the OS kernel to a specific version.
Examples:
Changing OS parameters.
Examples:
Collecting information on the node and performing other similar actions.
Configuring containerd.
Examples:
NodeGroupConfiguration settings
The NodeGroupConfiguration resource allows you to set the priority of the scripts being run and to limit their execution to specific node groups and OS types.
The script code is specified in the content parameter of the resource. When the script is created on the node, the contents of the content parameter are processed by the Go Template templating engine, which allows you to add an extra layer of logic when generating the script. During template processing, a context with a set of dynamic variables is available.
Variables available for use in templates:
.cloudProvider(for node groups with nodeTypeCloudEphemeralorCloudPermanent) — an array of cloud provider data..cri— the CRI in use (starting with Deckhouse 1.49, onlyContainerdis used)..kubernetesVersion— the Kubernetes version in use..nodeUsers— an array of data about node users added via the NodeUser resource..nodeGroup— an array of node group data.
{{- range .nodeUsers }}
echo 'Tuning environment for user {{ .name }}'
# Some code for tuning user environment.
{{- end }}Example of using bashbooster commands:
bb-event-on 'bb-package-installed' 'post-install'
post-install() {
bb-log-info "Setting reboot flag due to kernel was updated"
bb-flag-set reboot
}You can view the progress of script execution on the node in the bashible service log using the command:
journalctl -u bashible.serviceThe scripts themselves are located on the node in the /var/lib/bashible/bundle_steps/ directory.
The service decides whether to rerun the scripts by comparing the single checksum of all files located at /var/lib/bashible/configuration_checksum with the checksum stored in the Kubernetes cluster in the configuration-checksums secret of the d8-cloud-instance-manager namespace.
You can check the checksum with the following command:
d8 k -n d8-cloud-instance-manager get secret configuration-checksums -o yamlThe service compares the checksums every minute.
The checksum in the cluster changes every 4 hours, thereby rerunning the scripts on all nodes.
To force bashible to run on a node, delete the script checksum file using the following command:
rm /var/lib/bashible/configuration_checksumScript writing specifics
When writing scripts, consider the following specifics of how they are used in Deckhouse:
- Scripts in Deckhouse run every 4 hours or based on external triggers. Therefore, write scripts so that they check whether their changes are needed in the system before performing any actions, rather than making changes on every run.
- When choosing the priority of custom scripts, take into account the built-in scripts that perform various actions, including installing and configuring services. For example, if a script is supposed to restart a service and the service is installed by a built-in script with priority N, the custom script priority must be at least N+1; otherwise, the custom script will fail when a new node is deployed.