Todos os produtos
Search
Central de documentação

Container Service for Kubernetes:Criar um script personalizado para um pool de nós

Última atualização: Jun 27, 2026

Os clusters registrados do ACK One permitem conectar clusters Kubernetes locais ou de terceiros à plataforma de contêineres da Alibaba Cloud para gerenciamento unificado e operações de nuvem híbrida. Se a capacidade de computação local for limitada, expanda com pools de nós na nuvem usando ECS. Este tópico explica como criar scripts personalizados para pools de nós na nuvem.

Pré-requisitos

Antes de começar:

Limitações

  • Os scripts de exemplo suportam apenas sistemas operacionais que usam YUM (Yellowdog Updater, Modified) como gerenciador de pacotes.

  • Os scripts de exemplo aplicam-se somente a nós ECS comuns. Para nós acelerados por GPU, envie um ticket à equipe de P&D para obter um script personalizado.

Nós acelerados por GPU exigem drivers e plug-ins de dispositivo. Consulte Atualizar manualmente o driver NVIDIA de um nó .

Visão geral

image

O processo consiste em três etapas:

  1. Preparar o script do nó: adapte um script personalizado existente ou use um modelo de exemplo.

  2. Carregar o script em um servidor de arquivos acessível ao cluster registrado.

  3. Registrar o caminho do script no ConfigMap ack-agent-config para recuperação durante a expansão.

Escolha o procedimento adequado para a etapa 1:

Situação

Ação

Script de bootstrap existente

Siga a Etapa 1(A): adicione as variáveis de ambiente necessárias da Alibaba Cloud

Nenhum script de bootstrap existente

Siga a Etapa 1(B): baixe e personalize um exemplo

Etapa 1(A): Adicionar variáveis de ambiente da Alibaba Cloud a um script existente

O cluster registrado injeta quatro variáveis de ambiente durante a expansão para gerenciar o pool de nós.

Importante

A variável ALIBABA_CLOUD_PROVIDER_ID é obrigatória para o funcionamento do cluster registrado. Sem ela no script, o cluster não opera normalmente.

Variáveis de ambiente:

Variável

Obrigatória

Efeito se ausente

Valor de exemplo

ALIBABA_CLOUD_PROVIDER_ID

Sim

O cluster registrado não funciona normalmente

cn-shenzhen.i-wz92ewt14n9wx9mo***

ALIBABA_CLOUD_NODE_NAME

Sim

Os nós podem entrar em estado anormal

cn-shenzhen.192.168.1.***

ALIBABA_CLOUD_LABELS

Sim

O gerenciamento do pool de nós e o agendamento de cargas de trabalho podem falhar

alibabacloud.com/nodepool-id=np0e2031e952c4492bab32f512ce142,ack.aliyun.com=cc3df6d939b0d4463b493b82d0d670,alibabacloud.com/instance-id=i-wz960ockeekr3dok0***,alibabacloud.com/external=true,workload=cpu

ALIBABA_CLOUD_TAINTS

Sim

Os taints do pool de nós não entram em vigor

workload=ack:NoSchedule

Em ALIBABA_CLOUD_LABELS , apenas workload=cpu é personalizado (definido na configuração do pool de nós). Todos os outros rótulos são de sistema.

Adicione o bloco de injeção de variáveis conforme o método de instalação do cluster.

Cluster criado com kubeadm

Insira este bloco após a configuração principal do nó e antes de reiniciar o kubelet.

####### Begin: Alibaba Cloud environment variable injection

# Configure node labels, taints, node name, and provider ID.
KUBELET_CONFIG_FILE="/etc/sysconfig/kubelet"
if [[ $ALIBABA_CLOUD_LABELS != "" ]];then
  option="--node-labels"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_LABELS},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_LABELS} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_LABELS}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_TAINTS != "" ]];then
  option="--register-with-taints"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_TAINTS},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_TAINTS} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_TAINTS}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_NODE_NAME != "" ]];then
  option="--hostname-override"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_NODE_NAME},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_NODE_NAME} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_NODE_NAME}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_PROVIDER_ID != "" ]];then
  option="--provider-id"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_PROVIDER_ID},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_PROVIDER_ID} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_PROVIDER_ID}\"" $KUBELET_CONFIG_FILE
  fi
fi

####### End: Alibaba Cloud environment variable injection

Prossiga para a Etapa 2: Carregar o script.

Cluster instalado com arquivos binários

Para clusters instalados com arquivos binários do Kubernetes, modifique a configuração de inicialização do kubelet. O arquivo kubelet.service geralmente reside em /usr/lib/systemd/system/.

cat /usr/lib/systemd/system/kubelet.service EOF
# Custom configurations are not shown.
...
[Service]
ExecStart=/data0/kubernetes/bin/kubelet \
  # Add the following flags:
  --node-ip=${ALIBABA_CLOUD_NODE_NAME} \
  --hostname-override=${ALIBABA_CLOUD_NODE_NAME} \
  --node-labels=${ALIBABA_CLOUD_LABELS} \
  --provider-id=${ALIBABA_CLOUD_PROVIDER_ID} \
  --register-with-taints=${ALIBABA_CLOUD_TAINTS} \

  ....
  --v=4
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF

Prossiga para a Etapa 2: Carregar o script.

Etapa 1(B): Usar um script de exemplo

Caso não exista um script de bootstrap, utilize um dos exemplos abaixo. Os modelos abrangem Docker e containerd.

Coletar os valores necessários

Reúna três valores do seu cluster externo:

Etapa 1: Obter a versão do Kubernetes

Obtenha a versão do Kubernetes:

Para Kubernetes 1.18 ou posterior (use o rótulo control-plane):

kubectl get no $(kubectl get nodes -l node-role.kubernetes.io/control-plane -o json | jq -r '.items[0].metadata.name') -o json | jq -r '.status.nodeInfo.kubeletVersion'

Para versões anteriores ao Kubernetes 1.18 (use o rótulo master):

kubectl get no $(kubectl get nodes -l node-role.kubernetes.io/master -o json | jq -r '.items[0].metadata.name') -o json | jq -r '.status.nodeInfo.kubeletVersion'

Saída esperada:

v1.14.10

Salve o valor como KUBE_VERSION.

Etapa 2: Obter o runtime de contêiner e a versão

Para Kubernetes 1.18 ou posterior:

kubectl get no $(kubectl get nodes -l node-role.kubernetes.io/control-plane -o json | jq -r '.items[0].metadata.name') -o json | jq -r '.status.nodeInfo.containerRuntimeVersion'

Para versões anteriores ao Kubernetes 1.18:

kubectl get no $(kubectl get nodes -l node-role.kubernetes.io/master -o json | jq -r '.items[0].metadata.name') -o json | jq -r '.status.nodeInfo.containerRuntimeVersion'

Saída esperada:

docker://18.6.3      # Docker runtime
containerd://1.4.3   # containerd runtime

Salve o número da versão (sem o prefixo docker:// ou containerd://) como RUNTIME_VERSION.

Etapa 3: Gerar o comando kubeadm join

Importante

A flag --ttl 0 é obrigatória. Sem ela, o token de associação expira e o Auto Scaling para de funcionar.

kubeadm token create --ttl 0 --print-join-command

Saída esperada:

kubeadm join 192.168.8.XXX:6443 --token k8xsq8.4oo8va9wcqpb*** \
    --discovery-token-ca-cert-hash sha256:cb5fc894ab965dfbc4c194e1065869268f8845c3ec40f78f9021dde24610d***

Salve o resultado como KUBEADM_JOIN_CMD.

Script de exemplo: Docker

Substitua os três espaços reservados pelos valores coletados:

  • KUBE_VERSION — versão do Kubernetes (por exemplo, 1.21.0)

  • RUNTIME_VERSION — versão do Docker (por exemplo, 18.6.3)

  • KUBEADM_JOIN_CMD — comando completo kubeadm join ...

Expandir para visualizar o código

#!/bin/bash

# The Kubernetes version of the external cluster.
export KUBE_VERSION=KUBE_VERSION

# The Docker version of the external cluster.
export RUNTIME_VERSION=RUNTIME_VERSION

# The kubeadm join command.
export KUBEADM_JOIN_CMD=KUBEADM_JOIN_CMD

# Disable the firewall.
systemctl stop firewalld
systemctl disable firewalld
systemctl is-enabled firewalld

# Disable SELinux.
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0

# Disable swap partitions.
sed -i '/swap/s/^/#/g' /etc/fstab
swapoff -a

# Configure kernel parameters.
cat  /etc/sysctl.d/Kubernetes.conf EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness = 0
EOF

sysctl --system

# Install network and system utilities.
yum -y install conntrack ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
cat  /etc/modules-load.d/ipvs.conf EOF
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack
EOF

systemctl enable --now systemd-modules-load

# Configure the Docker YUM source.
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# Install Docker dependencies.
yum install -y yum-utils device-mapper-persistent-data lvm2

# View the available Docker versions.
yum list docker-ce --showduplicates | sort -r

# Install Docker.
yum install -y docker-ce-$RUNTIME_VERSION docker-ce-cli-$RUNTIME_VERSION containerd.io

# Configure the Docker daemon.
mkdir /etc/docker
cat  /etc/docker/daemon.json EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ],
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
EOF

mkdir -p /etc/systemd/system/docker.service.d

# Start Docker.
systemctl daemon-reload
systemctl restart docker
systemctl enable docker

# Configure the Kubernetes YUM source.
cat /etc/yum.repos.d/kubernetes.repo EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet-$KUBE_VERSION kubeadm-$KUBE_VERSION kubectl-$KUBE_VERSION --disableexcludes=kubernetes

# Configure kubelet.service.
cat /etc/systemd/system/kubelet.service EOF
# ! IMPORTANT !
# This configuration is managed and generated by ACK
# please do not edit it to avoid unexpected failures

[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=http://kubernetes.io/docs/

[Service]
ExecStart=/usr/bin/kubelet
Restart=always
StartLimitInterval=0
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

#  The environment variables of the registered cluster. Do not delete the settings.
# Configure node labels, taints, node name, and provider ID.
KUBELET_CONFIG_FILE="/etc/sysconfig/kubelet"
if [[ $ALIBABA_CLOUD_LABELS != "" ]];then
  option="--node-labels"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_LABELS},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_LABELS} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_LABELS}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_TAINTS != "" ]];then
  option="--register-with-taints"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_TAINTS},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_TAINTS} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_TAINTS}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_NODE_NAME != "" ]];then
  option="--hostname-override"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_NODE_NAME},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_NODE_NAME} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_NODE_NAME}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_PROVIDER_ID != "" ]];then
  option="--provider-id"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_PROVIDER_ID},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_PROVIDER_ID} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_PROVIDER_ID}\"" $KUBELET_CONFIG_FILE
  fi
fi
# The environment variables of the registered cluster. Do not delete the settings. 

systemctl enable kubelet
systemctl start kubelet

# Join the cluster.
$KUBEADM_JOIN_CMD

Script de exemplo: containerd

Substitua os três espaços reservados pelos valores coletados:

  • KUBE_VERSION — versão do Kubernetes (por exemplo, 1.21.0)

  • RUNTIME_VERSION — versão do containerd (por exemplo, 1.4.3)

  • KUBEADM_JOIN_CMD — comando completo kubeadm join ...

Expandir para visualizar o código

#!/bin/bash

# The Kubernetes version of the external cluster.
export KUBE_VERSION=KUBE_VERSION

# The containerd version of the external cluster.
export RUNTIME_VERSION=RUNTIME_VERSION

# The kubeadm join command.
export KUBEADM_JOIN_CMD=KUBEADM_JOIN_CMD

# Disable the firewall.
systemctl stop firewalld
systemctl disable firewalld
systemctl is-enabled firewalld

# Disable SELinux.
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0

# Disable swap partitions.
sed -i '/swap/s/^/#/g' /etc/fstab
swapoff -a

# Configure kernel parameters.
cat  /etc/sysctl.d/Kubernetes.conf EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness = 0
EOF

sysctl --system

# Install network and system utilities.
yum -y install conntrack ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
cat  /etc/modules-load.d/ipvs.conf EOF
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack
EOF

systemctl enable --now systemd-modules-load

# Install and configure containerd.
yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# Load required kernel modules.
cat /etc/modules-load.d/containerd.conf EOF
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter

# Install containerd.
yum install containerd.io-$RUNTIME_VERSION -y

# Configure the containerd client (crictl).
cat /etc/crictl.yaml EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
pull-image-on-create: false
disable-pull-on-run: false
EOF

# Configure containerd.
mkdir -p /etc/containerd
containerd config default  /etc/containerd/config.toml
# Use systemd to manage cgroups.
sed -i '/SystemdCgroup/s/false/true/g' /etc/containerd/config.toml
# Pull the sandbox image from Alibaba Cloud.
sed -i '/sandbox_image/s/registry.k8s.io/registry.aliyuncs.com\/google_containers/g' /etc/containerd/config.toml
sed -i 's#sandbox_image = "registry.k8s.io/pause:3.6"#sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"#' /etc/containerd/config.toml

# Start containerd.
systemctl enable containerd
systemctl start containerd

# Configure the Kubernetes YUM source.
cat /etc/yum.repos.d/kubernetes.repo EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum -y install kubeadm-$KUBE_VERSION kubectl-$KUBE_VERSION kubelet-$KUBE_VERSION

# Configure kubelet.service.
cat /etc/systemd/system/kubelet.service EOF
# ! IMPORTANT !
# This configuration is managed and generated by ACK
# please do not edit it to avoid unexpected failures

[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=http://kubernetes.io/docs/

[Service]
ExecStart=/usr/bin/kubelet
Restart=always
StartLimitInterval=0
RestartSec=10

[Install]
WantedBy=multi-user.target
EOF

#  The environment variables of the registered cluster. Do not delete the settings.
# Configure node labels, taints, node name, and provider ID.
KUBELET_CONFIG_FILE="/etc/sysconfig/kubelet"
if [[ $ALIBABA_CLOUD_LABELS != "" ]];then
  option="--node-labels"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_LABELS},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_LABELS} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_LABELS}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_TAINTS != "" ]];then
  option="--register-with-taints"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_TAINTS},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_TAINTS} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_TAINTS}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_NODE_NAME != "" ]];then
  option="--hostname-override"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_NODE_NAME},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_NODE_NAME} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_NODE_NAME}\"" $KUBELET_CONFIG_FILE
  fi
fi

if [[ $ALIBABA_CLOUD_PROVIDER_ID != "" ]];then
  option="--provider-id"
  if grep -- "${option}=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@${option}=@${option}=${ALIBABA_CLOUD_PROVIDER_ID},@g" $KUBELET_CONFIG_FILE
  elif grep "KUBELET_EXTRA_ARGS=" $KUBELET_CONFIG_FILE  /dev/null;then
    sed -i "s@KUBELET_EXTRA_ARGS=@KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_PROVIDER_ID} @g" $KUBELET_CONFIG_FILE
  else
    sed -i "/^\[Service\]/a\Environment=\"KUBELET_EXTRA_ARGS=${option}=${ALIBABA_CLOUD_PROVIDER_ID}\"" $KUBELET_CONFIG_FILE
  fi
fi
# The environment variables of the registered cluster. Do not delete the settings. 

systemctl enable kubelet
systemctl start kubelet

# Join the cluster.
$KUBEADM_JOIN_CMD

Etapa 2: Carregar o script

Carregue o script em um servidor de arquivos acessível ao cluster registrado. O Object Storage Service (OSS) é uma opção comum.

URL de exemplo:

https://kubelet-****.oss-cn-hangzhou-internal.aliyuncs.com/join-ecs-nodes.sh

Guarde a URL para a próxima etapa.

Etapa 3: Registrar o caminho do script

Importante

Conclua esta etapa antes de criar um pool de nós. Sem o registro do caminho do script, a expansão não recupera o arquivo e falha.

Defina addNodeScriptPath no ConfigMap ack-agent-config (namespace kube-system).

kubectl edit cm ack-agent-config -n kube-system

Configure addNodeScriptPath com a URL do seu script:

apiVersion: v1
data:
  addNodeScriptPath: https://kubelet-****.oss-cn-hangzhou-internal.aliyuncs.com/join-ecs-nodes.sh
kind: ConfigMap
metadata:
  name: ack-agent-config
  namespace: kube-system

Salve e feche o arquivo. O cluster registrado usa esse script para inicializar nós ECS durante a expansão.