问题描述
- 在Ubuntu上运行,我使用
kubeadm init
设置群集(主节点)并复制到/etc/kubernetes/admin.conf $HOME/.kube/config
上,使用kubectl
时一切都很好. - 但是,重新引导后,我的主节点的IP地址更改与
$HOME/.kube/config
中的更改不同,所以现在我无法再连接kubectl
- Running under Ubuntu I used
kubeadm init
to setup my cluster (master node) and copied over the/etc/kubernetes/admin.conf $HOME/.kube/config
and all was well when usingkubectl
. - However after a reboot my master node has had an IP address change which is not the same as what is in
$HOME/.kube/config
so now I can no longer connectkubectl
那么,有了新的IP地址后,如何重新生成admin.conf?运行kubeadm init
只会杀死所有我不想要的东西.
So how do I regenerate the admin.conf now that I have a new IP address? Running kubeadm init
will just kill everything which is not what I want.
推荐答案
您不想使用kubeadm reset
.这将重置所有内容,您将不得不重新开始配置集群.
You do not want to use kubeadm reset
. That will reset everything and you would have to start configuring your cluster again.
在您的情况下,请查看以下步骤:
Well, in your scenario, please have a look on the steps below:
-
nano /etc/hosts
(针对YOUR_HOSTNAME
更新您的新IP) 此文件中的 -
nano /etc/kubernetes/config
(与群集相关的配置设置)在寻找以下参数并相应地更新
nano /etc/hosts
(update your new IP againstYOUR_HOSTNAME
)nano /etc/kubernetes/config
(configuration settings related to your cluster) here in this file look for the following params and update accordingly
KUBE_MASTER="--master=http://YOUR_HOSTNAME:8080"
KUBE_ETCD_SERVERS="--etcd-servers=http://YOUR_HOSTNAME:2379" #2379 is default port
nano /etc/etcd/etcd.conf
(与etcd
相关的conf
)
KUBE_ETCD_SERVERS="--etcd-servers=http://YOUR_HOSTNAME/WHERE_EVER_ETCD_HOSTED:2379"
2379
是etcd
的默认端口.并且您可以在此处以逗号分隔的方式定义多个etcd
服务器
2379
is default port for etcd
. and you can have multiple etcd
servers defined here comma separated
重新启动kubelet
,apiserver
,etcd
服务.
最好使用hostname
而不是IP
以避免这种情况.
It is good to use hostname
instead of IP
to avoid such scenarios.
希望有帮助!
这篇关于我的kubernetes群集IP地址已更改,现在kubectl将不再连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!