简体   繁体   English

如何重新配置k8s节点的IP

[英]How to reconfigure the IP of a k8s node

I created a k8s installed by k0s on the aws ec2 instance.我在 aws ec2 实例上创建了一个由 k0s 安装的 k8s。 In order to make delivery new cluster faster, I try to make an AMI for it.为了更快地交付新集群,我尝试为它制作一个 AMI。

However, I started a new ec2 instance, the internal IP changed and the node become NotReady但是,我启动了一个新的ec2实例,内部IP发生了变化,节点变为NotReady

ubuntu@ip-172-31-26-46:~$ k get node
NAME               STATUS     ROLES    AGE   VERSION
ip-172-31-18-145   NotReady   <none>   95m   v1.21.1-k0s1
ubuntu@ip-172-31-26-46:~$

Would it be possible to reconfigure it?是否可以重新配置它?


Work around解决方法

I found a work around to make the AWS AMI working我找到了使 AWS AMI 正常工作的解决方法

Short answer简短的回答

  1. install node with kubelet's --extra-args使用 kubelet 的--extra-args安装节点
  2. update the kube-api to the new IP and restart the kubelet将 kube-api 更新为新的 IP 并重启 kubelet

Details:: 1详细信息:: 1

In the kubernete cluster, the kubelet plays the node agent node.在 kubernete 集群中, kubelet扮演节点代理节点。 It will tell kube-api "Hey, I am here and my name is XXX".它会告诉kube-api “嘿,我在这里,我的名字是 XXX”。

The name of a node is its hostname and could not be changed after created.节点的名称是它的主机名,创建后不能更改。 It could be set by --hostname-override .它可以由--hostname-override设置。

If you don't change the node name, the kube-api will try to use the hostname then got errors caused by old-node-name not found.如果您不更改节点名称, kube-api将尝试使用主机名,然后出现由old-node-name not found 导致的错误。

Details:: 2详细信息:: 2

To k0s, it put kubelet' KUBECONFIG in the /var/lib/k0s/kubelet.conf , there was a kubelet api server location到 k0s,它把 kubelet 的 KUBECONFIG 放在/var/lib/k0s/kubelet.conf中,有一个 kubelet api 服务器位置

server: https://172.31.18.9:6443

In order to connect a new kube-api location, please update it为了连接一个新的 kube-api 位置,请更新它

Did you check the kubelet logs?你检查 kubelet 日志了吗? Most likely it's a problem with certificates.很可能是证书的问题。 You cannot just make an existing node into ami and hope it will work since certificates are signed for specific IP.您不能仅仅将现有节点变成 ami 并希望它能够工作,因为证书是为特定的 IP 签名的。

Check out the awslabs/amazon-eks-ami repo on github.查看 github 上的awslabs/amazon-eks-ami存储库。 You can check out how aws does its k8s ami.您可以查看 aws 如何处理其 k8s ami。

There is a files/bootstrap.sh file in repo that is run to bootstrap an instance. repo 中有一个files/bootstrap.sh文件,用于引导实例。 It does all sort of things that are instance specific which includes getting certificates.它会做各种特定于实例的事情,包括获取证书。

If you want to "make delivery new cluster faster" , I'd recommend to create an ami with all dependencies but without an actual k8s boostraping.如果您想“更快地交付新集群” ,我建议创建一个包含所有依赖项但没有实际 k8s 助推的 ami。 Install the k8s (or k0s in your case) after you start the instance from ami, not before.在从 ami 启动实例之后安装 k8s(或在您的情况下为 k0s),而不是之前。 (Or figure out how to regenerate certs and configs that are node specific.) (或者弄清楚如何重新生成特定于节点的证书和配置。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM