The connection to the server localhost:8080 was refused - did you specify the right host or port?

解决报错:

The connection to the server localhost:8080 was refused - did you specify the right host or port?

1.实验环境

10.0.0.7 master
10.0.17 node01
10.0.0.27 node02

2.只有在node节点上操作kubectl get pods会报错

#master
[root@master ~]#kubectl  get pods
No resources found in default namespace.```

#node01
[root@nide01 ~]#kubectl  get pops
The connection to the server localhost:8080 was refused - did you specify the right host or port?

#node02
[root@nide02 ~]#kubectl  get pops
The connection to the server localhost:8080 was refused - did you specify the right host or port?

3 .Node节点上缺少/etc/kubernetes/admin.conf文件

#把master上的/etc/kubernetes/admin.conf文件传送到node上去
[root@master ~]# scp  /etc/kubernetes/admin.conf  10.0.0.17:/etc/kubernetes/

[root@master ~]# scp  /etc/kubernetes/admin.conf  10.0.0.27:/etc/kubernetes/

4 .使得node节点上/etc/kubernetes/admin.conf文件生效

#node01
[root@nide01 ~]#echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
[root@nide01 ~]#source /etc/profile
#node02
[root@nide02 ~]#echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
[root@nide02 ~]#source /etc/profile

5.验证

#生成一个名为demoapp应用
[root@node01 ~]#kubectl  create deployment demoapp --image="ikubernetes/demoapp:v1.0" 
deployment.apps/demoapp created

[root@node02 ~]#kubectl  get pods
NAME                       READY   STATUS    RESTARTS   AGE
demoapp-5f7d8f9847-gtb2l   1/1     Running   0          16m

#成功   ✌( •̀ ω •́ )y✌

你可能感兴趣的:(kubernetes,运维,负载均衡,服务器)