Kubernetes遇到过的坑

Kubernetes遇到过的坑

遇到的问题

今天在测试kubernetes时,在从节点执行kubectl get pods命令出现如下错误:

[root@centos6 etcd-v3.4.7-linux-amd64]# kubectl get pods
W0504 22:52:02.915343   59377 loader.go:223] Config not found: /etc/kubernetes/admin.conf
The connection to the server localhost:8080 was refused - did you specify the right host or port?

根据反馈得知找不到/etc/kubernetes/admin.conf这个文件,我之前搭建集群时是没有错误的,现在不知道为啥没有了。

解决方法

虽然不知道为啥这个文件莫名其妙消失了,但是无妨,见招拆招吧直接。

首先在该从节点建立此文件;再将主节点的/etc/kubernetes/admin.conf文件内容copy过来;最后执行

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile

立即重启

source ~/.bash_profile

再次验证

[root@centos6 kubernetes]# kubectl get pods
NAME                                     READY   STATUS    RESTARTS   AGE
frontend-2zjjs                           1/1     Running   3          16d
frontend-4tfhb                           1/1     Running   3          16d
frontend-j5srv                           1/1     Running   2          16d
frontend-pm82l                           1/1     Running   2          16d
nginx-deployment-54f57cf6bf-42z85        1/1     Running   3          16d
nginx-deployment-54f57cf6bf-kflt4        1/1     Running   3          16d
nginx-deployment-54f57cf6bf-rzhjj        1/1     Running   3          16d
nginx-deployment-54f57cf6bf-wlz76        1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-9mgzn   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-bzmq2   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-c7tdc   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-frxj4   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-fxdw2   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-gxkff   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-nnrnd   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-pqdtd   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-rmjq2   1/1     Running   3          16d
test-nginx-deployment-54f57cf6bf-t2l4d   1/1     Running   3          16d
web-0                                    0/1     Pending   0          51d

执行成功!

posted @ 2020-05-05 00:26  wind-zhou  Views(13575)  Comments(0Edit  收藏  举报