To use kubeadm with the Alibaba Cloud CloudProvider, you must configure the kubelet to include the provider ID and set the cloud provider to external.
1. Configure Kubelet
For each node, you must update the kubelet configuration to include --provider-id (formatted as region-id.instance-id) and --hostname-override.
2. Initialize Cluster
Use a kubeadm.conf file with the following requirements:
- Set
cloudProvider: external. - (Best Practice) Set
imageRepository: registry-vpc.${region}.aliyuncs.com/acs to pull images faster within Alibaba Cloud regions.
Run the initialization command:
kubeadm init --config kubeadm.conf
if [[ 0 -eq `grep '\--provider-id' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf|wc -l` ]]; then
META_EP=http://100.100.100.200/latest/meta-data
provider_id=`curl -s $META_EP/region-id`.`curl -s $META_EP/instance-id`
sed -i "s/--cloud-provider=external/--cloud-provider=external --hostname-override=${provider_id} --provider-id=${provider_id}/g" /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl daemon-reload
systemctl restart kubelet
fi