我刚刚通过kubectl
安装了Ubuntu 64 (Linux)
。
我遵循了在线Kubernetes指南,但是主机出现错误。第一步(安装kubectl)之后,当我检查kubectl版本时,这是消息(我尚未安装和部署minikube,因为我没有根据此问题进行连接):
root@ubuntu:~# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
有人有同样的问题吗?我该如何解决?
答案 0 :(得分:11)
其背后的原因是kubectl version
同时打印Client Version
和Server Version
(kubernetes版本)。当您只安装kubectl时,它只是kubernets客户端。如果您安装了kubernetes集群,它将同时打印kubectl版本和kubernetes版本。
如果只想打印客户端版本,请使用以下命令:
kubectl version --client=true
该错误表示kubectl tried to contact the kubernetes server to get its version but couldn't connect. Are you specifying the right host or port to connect to the kubernetes server.
错误的原因是您尚未在Mac上安装kubernetes集群。您刚刚安装了kubectl,它只是访问kubernetes集群的客户端。一旦安装了kubernetes集群,kubectl版本的输出将如下所示:
[root@ip-10-0-1-138 centos]# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1",
GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:05:37Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
如果要在Mac上安装完整的kubernetes集群,请尝试minikube在本地安装集群。
答案 1 :(得分:0)
当 Kubectl 命令无法在用户的 .kube
文件夹中找到配置文件时,会发生这种情况。以下是您的用户需要执行的步骤:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
或者如果您是 root 用户:
export KUBECONFIG=/etc/kubernetes/admin.conf