今天在Kubernetes的从节点上运行命令【kubectl】出现了如下错误
[root@p22650v /home/zhu/k8s]# kubectl create -f k8stranscode-rc.yaml
The connection to the server 10.209.213.55:443 was refused - did you specify the right host or port?
出现这个问题的原因是kubectl命令需要使用kubernetes-admin来运行,解决方法如下,将主节点中的【/etc/kubernetes/admin.conf】文件拷贝到从节点相同目录下,然后配置环境变量:
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
立即生效
source ~/.bash_profile
接着再运行kubectl命令就OK了
[root@p22650v /home/zhu/k8s]# kubectl get pods
NAME READY STATUS RESTARTS AGE
curl-66959f6557-bmpb6 1/1 Running 1 14d
my-nginx-64fc468bd4-2cslw 1/1 Running 0 14d
my-nginx-64fc468bd4-n9r4q 1/1 Running 0 14d
test-67c9c8c7b-rvvww 0/2 ImagePullBackOff 0 30m
get pod