"authenticated as: anonymous Groups that you are in" 检查 kubectl 版本时出错

"authenticated as: anonymous Groups that you are in" error when checking kubectl version

我正在尝试在我的机器中设置 kubectl 工具以远程管理 Kubernetes 集群并使用 Helm。我正在 Ubuntu 16.04 机器上尝试。

我正在关注来自以下 link、

的官方 Kubernetes 文档

https://kubernetes.io/docs/tasks/tools/install-kubectl/

我运行以下命令,

sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl

然后当我 运行 'kubectl version' 命令验证安装后,我得到以下信息,

Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", 
GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", 
BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", 
Platform:"linux/amd64"}
Error from server (Forbidden): <html><head><meta http-equiv='refresh' 
content='1;url=/login?from=%2Fversion%3Ftimeout%3D32s'/> 
<script>window.location.replace('/login?from=%2Fversion%3Ftimeout%3D32s'); 
</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
 You are authenticated as: anonymous
 Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
-->

也没有在机器中找到“~/.kube/config”文件。

为什么在检查 kubectl 版本时出现此身份验证错误?

您必须手动将 .kube/ 目录从集群节点复制到本地 ~/.kube

如果master节点上没有.kube/,从/etc/kubernetes/kube.conf中复制

mkdir $HOME/.kube
scp root@<master-public-ip>:/etc/kubernetes/kubelet.conf $HOME/.kube/config

你也可以通过传入--kubeconfig参数来定义kubeconfig的文件路径,即

kubectl version --kubeconfig ~/.kube/config