sh 手动回收AKS节点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 手动回收AKS节点相关的知识,希望对你有一定的参考价值。

SSH_KEY_PUBLIC=~/.ssh/id_rsa.pub
SSH_KEY_PRIVATE=~/.ssh/id_rsa
AZURE_RG=test
AZURE_AKS_CLUSTER_NAME=test
AKS_AGENT_PREFIX=sbox

kubectl get nodes --output wide

CLUSTER_RESOURCE_GROUP=$(az aks show \
  --resource-group ${AZURE_RG} \
  --name ${AZURE_AKS_CLUSTER_NAME} \
  --query nodeResourceGroup \
  --output tsv)

az vm list \
  --resource-group ${CLUSTER_RESOURCE_GROUP} \
  --output table

# Also make note of IP address of same node
CLUSTER_NODE= # Pick one from above list and put value here

az vm user update \
  --resource-group ${CLUSTER_RESOURCE_GROUP} \
  --name ${CLUSTER_NODE} \
  --username azureuser \
  --ssh-key-value ${SSH_KEY_PUBLIC}

kubectl drain ${CLUSTER_NODE} \
  --ignore-daemonsets \
  --delete-local-data

# WAIT FOR ALL PODS TO BE READY!

# In new terminal window run....
kubectl run -it --rm aks-ssh \
  --image=debian \
  --generator=run-pod/v1 \
  --labels="app=basshtion"
  
# Back in the first terminal
kubectl cp ${SSH_KEY_PRIVATE} aks-ssh:/id_rsa

# over to the second terminal window
# which should now be running a debian shell inside aks-ssh
chmod 600 id_rsa && \
  apt-get update && \
  apt-get install openssh-client -y
ssh -i id_rsa azureuser@<IP address noted above>

# This now drops you into the shell of the node
# You should see something like this
# *** System restart required ***
sudo reboot

# You will be kicked out of the node
# and returned to the debian shell.
# Type ctrl+D to disconnect the shell which will terminate the pod

# Back in the first terminal
# Keep an eye on the KERNEL-VERSION until it changes
watch "kubectl get nodes -o wide"

# Finally uncordon the node
kubectl uncordon ${CLUSTER_NODE}

以上是关于sh 手动回收AKS节点的主要内容,如果未能解决你的问题,请参考以下文章

Terraform 在 AKS 节点资源组中创建入口应用程序网关

可以用作 AKS 节点的最便宜的 VM 是啥?

AKS初体验:登录到node节点的几种方式

Shell (ssh) 到 Azure AKS (Kubernetes) 群集工作节点

使用 AKS 管理容器时的问题

AKS 中的 Ocelot API 网关实现