[英]kubectl query results in "unauthorized" with GCP cluster even after `get-credentials`
I get You must be logged in to the server (Unauthorized)
for commands like kubectl get pods -A
even after having followed many steps by step guides and tried various solutions.我知道
You must be logged in to the server (Unauthorized)
才能使用kubectl get pods -A
类的命令,即使在遵循了许多分步指南并尝试了各种解决方案之后也是如此。 He is more detail on what I did and what works / does not work:他更详细地说明了我做了什么以及什么有效/无效:
gcloud container clusters create <cluster_name> --zone <zone> --project <project_name>
minikube start
kubectl proxy --port=8080 &
gcloud container clusters get-credentials <cluster_name> --zone <zone> --project <project_name>
gcloud auth login
Do login in browser在浏览器中登录
Checking:检查:
-> % kubectl config current-context
gke_<project_name>_<zone>_<cluster_name>
-> % curl http://localhost:8080/api/
{
"kind": "APIVersions",
"versions": [
"v1"
],
"serverAddressByClientCIDRs": [
{
"clientCIDR": "0.0.0.0/0",
"serverAddress": "xxx.xxx.x.x:8443"
}
]
}%
-> % kubectl cluster-info
Kubernetes control plane is running at https://xx.xxx.xxx.xxx
GLBCDefaultBackend is running at https://xx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy
KubeDNS is running at https://xx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://xx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
So this works.所以这行得通。 But what does not work:
但是什么不起作用:
-> % kubectl get pods -A
error: You must be logged in to the server (Unauthorized)
What gives?是什么赋予了?
I spent hours now trying to find a solution.我现在花了几个小时试图找到解决方案。 The solutions I found reference
/etc/kubernetes/admin.conf
我找到的解决方案参考
/etc/kubernetes/admin.conf
I don't have the directory /etc/kubernetes
.我没有目录
/etc/kubernetes
。 (I do run Linux) (我确实运行 Linux)
Any ideas?有任何想法吗?
I think the answer is: I was using kubectl
as an alias for minikube kubectl
but after removing the alias which kubectl
shows /home/<user>/google-cloud-sdk/bin/kubectl
.我认为答案是:我使用
kubectl
作为minikube kubectl
的别名,但在删除which kubectl
显示的别名后/home/<user>/google-cloud-sdk/bin/kubectl
。 Now everything seems to work.现在一切似乎都奏效了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.