切换命名空间后无法链接节点

报错如下

[root@master1 opt]# kubectl run snowflake --image=nginx:1.7.9 --replicas=2
error: failed to discover supported resources: Get http://localhost:8080/apis/apps/v1?timeout=32s: dial tcp [::1]:8080: connect: connection refused
[root@master1 opt]# kubectl get deployment
The connection to the server localhost:8080 was refused - did you specify the right host or port?

解决方法:

##把master1 admin.conf复制到其他master节点 并执行环境变量“主节点同上”
主节点操作

cat /etc/kubernetes/admin.conf 
scp -r /etc/kubernetes/admin.conf 192.168.0.43:/etc/kubernetes/

三个master操作

[root@master1 opt]# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >>~/.bash_profile
[root@master1 opt]# source ~/.bash_profile 
[root@master1 opt]# kubectl run snowflake --image=nginx:1.7.9 --replicas=2
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/snowflake create