Creating a Node Injection Script
Background
If you need to install some tools or perform custom security hardening on a node in advance, you need to inject some scripts when creating the node. CCE allows you to inject pre-installation and post-installation scripts when creating a node. However, this function has the following restrictions:
- The characters of the injection scripts are limited.
- The injected script content needs be frequently modified to meet various requirements and scenarios. However, injection scripts of the CCE node pool are fixed and do not support frequent modifications.
Solution
This section describes how to use CCE and OBS to provide a simplified, scalable, and easy-to-maintain solution, so that you can perform custom operations on CCE nodes.
Store the pre-installation and post-installation scripts in OBS. During node pool creation, CCE automatically pulls and executes the scripts stored in OBS based on the configured injection scripts. In this way, the configuration of the CCE node pool does not need to be changed. If there are new requirements, you only need to update the scripts in OBS.

Suggestions on Maintaining OBS Buckets
- If there is no OBS bucket dedicated for O&M, create an OBS bucket dedicated for O&M.
- Create a multi-level directory tools/cce in the bucket to represent CCE-specific tools for easy maintenance. You can also store other tool scripts in this directory later.
Precautions
- If the custom operation implemented by the script fails, the normal service running is affected. You are advised to add a check program at the end of the script. If the check fails, stop the kubelet process in the post-installation script to prevent services from being scheduled to the node.
systemctl stop kubelet-monitor
systemctl stop kubelet
- Do not include sensitive information in the scripts to prevent information leakage.
Procedure
- Create an OBS bucket.
- Upload the pre-installation and post-installation scripts. The pre_install.sh and post_install.sh scripts are used as examples. Figure 1 Uploading scripts
- Configure a read-only security policy for the scripts to ensure that the scripts can be downloaded without entering a password on the CCE nodes but cannot be downloaded from the Internet.
- Configure a policy for the tools/cce directory and select a read-only policy template. Figure 2 Configuring an object policy
- Modify the configuration information about the anonymous user, specified objects, and conditions. Figure 3 Anonymous user
Figure 4 Specified objects
Figure 5 Conditions
Two conditions are set: UserAgent and SourceIp.- UserAgent functions in the similar way as a key. The specified User-Agent request header and the corresponding key value must be carried during access.
- SourceIp is used to prevent access from external networks. Set this parameter to 100.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16, among which 100.0.0.0/8 indicates the private network address of HUAWEI CLOUD. 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 are common private network addresses.
For details about how to configure an OBS policy, see Configuring an Object Policy and Bucket Policy Parameters.
- Configure a policy for the tools/cce directory and select a read-only policy template.
- Configure the pre-installation script and post-installation script when creating a node pool on CCE.
Enter the following scripts in the Advanced ECS Settings on the Create Node Pool page:

In the scripts below, the curl command is run to download pre_install.sh and post_install.sh from OBS to the /tmp directory, and then pre_install.sh and post_install.sh are executed.
Pre-installation script:
curl -H "User-Agent: ccePrePostInstall" https://ops-cce.obs.cn-north-4.myhuaweicloud.com/tools/cce/pre_install.sh -o /tmp/pre_install.sh && bash -x /tmp/pre_install.sh > /tmp/pre_install.log &2>1
Post-installation script:
curl -H "User-Agent: ccePrePostInstall" https://ops-cce.obs.cn-north-4.myhuaweicloud.com/tools/cce/post_install.sh -o /tmp/post_install.sh && bash -x /tmp/post_install.sh > /tmp/post_install.log &2>1
- The actual value of User-Agent must be configured based on the OBS bucket policy.
- The bucket address in the link must be configured based on site requirements.
Last Article: Interconnecting CCE with Helm
Next Article: Networking
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.