繁体   English   中英

Kubectl 命令抛出错误:无法连接到服务器:获取凭据:执行:退出状态 2

[英]Kubectl command throwing error: Unable to connect to the server: getting credentials: exec: exit status 2

我正在进行 EKS/Kubectl 的实验室设置,在完成集群构建后,我运行以下命令:

> kubectl get node

And I get the following error:
Unable to connect to the server: getting credentials: exec: exit status 2

此外,我确信这是一个配置问题,

kubectl version
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help
aws: error: argument operation: Invalid choice, valid choices are:

create-cluster                           | delete-cluster                          
describe-cluster                         | describe-update                         
list-clusters                            | list-updates                            
update-cluster-config                    | update-cluster-version                  
update-kubeconfig                        | wait                                    
help                                    
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.1", GitCommit:"d224476cd0730baca2b6e357d144171ed74192d6", GitTreeState:"clean", BuildDate:"2020-01-14T21:04:32Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"darwin/amd64"}
Unable to connect to the server: getting credentials: exec: exit status 2

请告知故障排除的后续步骤。

请删除缓存文件夹中存在的文件夹

~/.aws/cli/cache

你准备好kubectl配置文件了吗?

通常我们将它放在~/.kube/config ,该文件包括集群端点、证书、上下文、管理员用户等。

此外,请阅读此文档: https : //docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html

你能检查一下你的 ~/.kube/config 文件吗?

假设您已经使用 minikube 启动本地集群,如果您的配置可用,您应该不会收到服务器错误。

示例配置文件

apiVersion: v1
    clusters:
    - cluster:
        certificate-authority: /Users/singhvi/.minikube/ca.crt
        server: https://127.0.0.1:32772
      name: minikube
    contexts:
    - context:
        cluster: minikube
        user: minikube
      name: minikube
    current-context: minikube
    kind: Config
    preferences: {}
    users:
    - name: minikube
      user:
        client-certificate: /Users/singhvi/.minikube/profiles/minikube/client.crt
        client-key: /Users/singhvi/.minikube/profiles/minikube/client.key

您需要更新/重新创建本地 kubeconfig。 就我而言,我删除了整个~/.kube/config并按照本教程进行操作:

https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html

对我来说,运行kubectl get nodeskubectl cluster-info会给我以下错误。

Unable to connect to the server: getting credentials: exec: executable kubelogin not found

It looks like you are trying to use a client-go credential plugin that is not installed.

To learn more about this feature, consult the documentation available at:
      https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins

kubectl 获取节点给出错误

我做了以下事情来解决这个问题。

  1. 删除了~/.kube/中的所有内容。 在我的例子中,它是一台 windows 机器,所以它的 C:\Users\nis.kube。 这里 nis 是我登录的用户名。

  2. 按如下方式运行获取凭据命令。

    az aks get-credentials --resource-group terraform-aks-dev --name terraform-aks-dev-aks-cluster --admin

最后注意--admin 没有它,它给了我同样的错误。

现在上面的两个命令正在工作。

参考: https://blog.baeke.info/2021/06/03/a-quick-look-at-azure-kubelogin/

我有同样的问题,问题是在 my.aws/credentials 文件中有多个用户,并且对 EKS (admin_test) 集群具有权限的用户不是默认用户。 因此,就我而言,我使用环境变量将“admin_test”用户设置为 CLI 中的默认用户:

export $AWS_PROFILE='admin_test'

之后,我使用以下命令检查了默认用户:

aws sts get-caller-identity

最后,我能够使用kubectl get nodes命令获取节点。

参考: https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html

在 EKS 中,您可以使用以下命令检索您的 kubectl 凭证:

% aws eks update-kubeconfig --name cluster_name
Updated context arn:aws:eks:eu-west-1:xxx:cluster/cluster_name in /Users/theofpa/.kube/config

您可以使用以下方法检索您的集群名称:

% aws eks list-clusters
{
    "clusters": [
        "cluster_name"
    ]
}

就我而言,因为我使用的是 azure(不是 aws),所以我必须安装“kubelogin”来解决问题。

“kubelogin”是一个实现 azure 身份验证的 client-go credential (exec) 插件。 这个插件提供了 kubectl 中没有的特性。 它在 kubectl v1.11+ 上受支持

我有同样的错误并通过将我的 awscli 升级到最新版本解决了它。

删除和添加~/.aws/credentials文件为我解决了这个问题。

rm ~/.aws/credentials
touch ~/.aws/credentials

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM