Kubectl command throwing error: Unable to connect to the server: getting credentials: exec: exit status 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

请告知下一步的故障排除步骤。

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

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

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

请删除存在于

中的缓存文件夹文件夹

~/.aws/cli/cache

你能检查一下你的 ~/.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

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

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

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

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