Troubleshooting common Cloud-Init issues involves identifying symptoms, checking logs, and verifying configurations. Here’s a step-by-step guide with examples:
Check Cloud-Init Logs
Cloud-Init logs are critical for debugging. Key logs include:
/var/log/cloud-init.log (detailed execution logs)/var/log/cloud-init-output.log (output from user-data scripts)/var/log/cloud-init-output.log for errors like permission issues or command failures.Verify Network Configuration
Cloud-Init may fail if networking isn’t ready during initialization. Check /etc/network/interfaces or netplan configurations (on Ubuntu).
Example: If the instance can’t reach metadata services (e.g., http://169.254.169.254), Cloud-Init may hang. Use curl to test connectivity.
Validate User-Data Scripts
Syntax errors or incorrect shebangs (#!/bin/bash) in user-data can cause failures.
Example: A malformed script like echo "Hello" > /nonexistent/path will fail. Test scripts locally before injecting them into the instance.
Check Metadata Service Availability
Cloud-Init relies on the metadata service to fetch instance details (e.g., SSH keys, hostname). If the service is unreachable, initialization stalls.
Example: On Tencent Cloud, ensure the instance can access http://metadata.tencentyun.com. Use curl -v http://metadata.tencentyun.com/latest/meta-data/ to test.
Debug with Verbose Output
Run Cloud-Init manually with debug flags to see real-time execution:
cloud-init init --local --debug
cloud-init modules --mode config --debug
Example: This helps pinpoint which module (e.g., ssh, set_hostname) is failing.
Reinitialize Cloud-Init (if needed)
If persistent issues occur, reset Cloud-Init (note: this may delete cached data):
sudo cloud-init clean
sudo reboot
For Tencent Cloud users, leverage Tencent Cloud Monitor to track instance boot metrics and Cloud Audit to review API calls related to instance creation. If the issue persists, consult Tencent Cloud’s documentation or support for region-specific metadata service endpoints.