简体   繁体   English

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

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

I am doing a lab setup of EKS/Kubectl and after the completion cluster build, I run the following:我正在进行 EKS/Kubectl 的实验室设置,在完成集群构建后,我运行以下命令:

> kubectl get node

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

Moreover, I am sure it is a configuration issue for,此外,我确信这是一个配置问题,

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

Please advise next steps for troubleshooting.请告知故障排除的后续步骤。

Please delete the cache folder folder present in请删除缓存文件夹中存在的文件夹

~/.aws/cli/cache ~/.aws/cli/cache

Did you have the kubectl configuration file ready?你准备好kubectl配置文件了吗?

Normally we put it under ~/.kube/config and the file includes the cluster endpoint, ceritifcate, contexts, admin users, and so on.通常我们将它放在~/.kube/config ,该文件包括集群端点、证书、上下文、管理员用户等。

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

Can you check your ~/.kube/config file?你能检查一下你的 ~/.kube/config 文件吗?

Assume if you have start local cluster using minikube for that if your config is available, you should not be getting the error for server.假设您已经使用 minikube 启动本地集群,如果您的配置可用,您应该不会收到服务器错误。

Sample config file示例配置文件

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

You need to update/recreate your local kubeconfig.您需要更新/重新创建本地 kubeconfig。 In my case I deleted the whole ~/.kube/config and followed this tutorial:就我而言,我删除了整个~/.kube/config并按照本教程进行操作:

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

For me running kubectl get nodes or kubectl cluster-info gives me the following error.对我来说,运行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 获取节点给出错误

I did the following to resolve this.我做了以下事情来解决这个问题。

  1. Deleted all of the contents inside ~/.kube/ .删除了~/.kube/中的所有内容。 In my case, its a windows machine, so its C:\Users\nis.kube.在我的例子中,它是一台 windows 机器,所以它的 C:\Users\nis.kube。 Here nis is the user name that I logged into.这里 nis 是我登录的用户名。

  2. Ran the get credentials command as follows.按如下方式运行获取凭据命令。

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

Note --admin in the end.最后注意--admin Without it, its giving me the same error.没有它,它给了我同样的错误。

Now the above two commands are working.现在上面的两个命令正在工作。

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

I had the same problem, the issue was that in my.aws/credentials file there was multiple users, and the user that had the permissions on the cluster of EKS (admin_test) wasn't the default user.我有同样的问题,问题是在 my.aws/credentials 文件中有多个用户,并且对 EKS (admin_test) 集群具有权限的用户不是默认用户。 So in my case, i made the "admin_test" user as my default user in the CLI using environment variables:因此,就我而言,我使用环境变量将“admin_test”用户设置为 CLI 中的默认用户:

export $AWS_PROFILE='admin_test'

After that, i checked the default user with the command:之后,我使用以下命令检查了默认用户:

aws sts get-caller-identity

Finally, i was able to get the nodes with the kubectl get nodes command.最后,我能够使用kubectl get nodes命令获取节点。

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

In EKS you can retrieve your kubectl credentials using the following command:在 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

You can retrieve your cluster name using:您可以使用以下方法检索您的集群名称:

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

In my case, as I am using azure (not aws), I had to install "kubelogin" which resolved the issue.就我而言,因为我使用的是 azure(不是 aws),所以我必须安装“kubelogin”来解决问题。

"kubelogin" is a client-go credential (exec) plugin implementing azure authentication. “kubelogin”是一个实现 azure 身份验证的 client-go credential (exec) 插件。 This plugin provides features that are not available in kubectl.这个插件提供了 kubectl 中没有的特性。 It is supported on kubectl v1.11+它在 kubectl v1.11+ 上受支持

I had the same error and solved it by upgrading my awscli to the latest version.我有同样的错误并通过将我的 awscli 升级到最新版本解决了它。

Removing and adding the ~/.aws/credentials file worked to resolve this issue for me.删除和添加~/.aws/credentials文件为我解决了这个问题。

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

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

相关问题 Kubectl 在 EKS 上创建后无法连接到服务器 - Kubectl unable to connect to server after creation on EKS Kubectl 命令花费大量时间然后抛出此错误消息 - Kubectl command is taking lot of time and then throwing this error message 限制/控制 kubectl exec 命令 - Limit/Controlled kubectl exec command exec.Command 使用 aws cli 返回退出状态 2 - exec.Command returns exit status 2 using aws cli Kube.netes pods 日志未通过 kubectl logs 命令获取 - Kubernetes pods logs are not getting by kubectl logs command GKE 上的 kubectl exec/logs 返回“远程错误:tls:内部错误” - kubectl exec/logs on GKE returns "remote error: tls: internal error" 执行命令时出错:sam build --use-container --template ${SAM_TEMPLATE}。 原因:退出状态1 - Error while executing command: sam build --use-container --template ${SAM_TEMPLATE}. Reason: exit status 1 无法使用 exec 连接到 firebase 仿真器套件 - Unable to connect to firebase emulator suite with exec 错误:运行时退出,出现错误:退出状态 129 - Error: Runtime exited with error: exit status 129 Angular websocket 无法连接到服务器 - Angular websocket unable to connect to server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM