使用更改了 ip 的 kubectl cmd 时无法连接到 k8s 服务器

问题描述 投票:0回答:0

my vm ip 不断变化,这是无法避免的。我之前的 ip 是 192.168.1.75,我能够使用“kubectl get pods”连接到 k8s,输出是正确的。

但现在我在不同的网络中,IP 10.160.194.67 不同。当我尝试连接时,出现以下错误

/root# kubectl get pod
Unable to connect to the server: dial tcp 192.168.1.75:6443: connect: no route to host
/root#

修复我刚刚在 /root/.kube/config 文件中更新了新的 ip。但现在它抱怨证书

/root# kubectl   get pod
Unable to connect to the server: x509: certificate is valid for 10.96.0.1, 192.168.1.75, not 10.160.194.67
/root#

我知道这个证书对新 IP 不再有效。我的问题是如何为这个特定的 ip 获取新证书并在此处替换?

正如我所说,我需要一个解决方案,这样每当我的 IP 发生变化时,我都需要修改我的配置文件才能工作。就我而言,保持 IP 不变是不可能的。

谢谢

kubernetes kubectl
© www.soinside.com 2019 - 2024. All rights reserved.