简体   繁体   English

即使在“get-credentials”之后,kubectl 查询也会导致 GCP 集群“未经授权”

[英]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.

相关问题 在 Bitbucket 管道中执行 gcloud 命令 `clusters get-credentials` 失败并带有 --zone 选项 - Executing gcloud command `clusters get-credentials` in Bitbucket Pipeline is failing with --zone option 为什么 gcloud container clusters get-credentials 会弄乱我的 Linux 用户权限? - Why gcloud container clusters get-credentials messes up my Linux user permissions? 如何让 kubectl 登录到 AWS EKS 集群? - How do you get kubectl to log in to an AWS EKS cluster? 如何使用 gcp auth 插件删除 kubectl 中的警告? - How to remove warning in kubectl with gcp auth plugin? 在 EKS 上部署 Istio bookinfo 应用程序后,`kubectl get svc` 显示应用程序的服务,但 `Kubectl get pods` 返回 `no resources found` - After deploying Istio bookinfo application on EKS, `kubectl get svc` displays the app's services but `Kubectl get pods` returns `no resources found` AWS Web 身份联合与 GCP ServiceAccount 凭证 - AWS Web Identity Federation with GCP ServiceAccount Credentials 如何轻松切换 gcloud / kubectl 凭据 - How to easily switch gcloud / kubectl credentials GCP 仪表板查询编辑器 - GCP dashboard Query editor 无法在 GCP 上创建 OpenShift 集群 - Unable to create OpenShift Cluster on GCP 如何使用 kubectl 描述 Kube.netes 集群? - How to describe a Kubernetes cluster using kubectl?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM