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

19,786

Solution 1

Can you check your ~/.kube/config file?

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.

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

Solution 2

Please delete the cache folder folder present in

~/.aws/cli/cache

Solution 3

Did you have the kubectl configuration file ready?

Normally we put it under ~/.kube/config and the file includes the cluster endpoint, ceritifcate, contexts, admin users, and so on.

Furtherly, read this document: https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html

Share:
19,786

Related videos on Youtube

Louis Preston Thornton III
Author by

Louis Preston Thornton III

By Day: I am a CHEF Automation guy who tackles such jobs as Automating HP Openview Products such as HP Operations Manager i (OMi) and Network Node Manager i (NNMi) in addition to anything else that comes my way in command line syntax. More recently, not knowing anything about test automation other than "Inspec" used within CHEF, I discovered Selenium Web Driver where I quick saw the light, and started using it to complete post Chef configuration. Once Chef has the base infrastructure up and running, I am able to use Selenium Web driver to open a web browser and finish configuring a given application. By Night: I am a Pastor/Teacher of the Word of God. I love to share the good news of Christ and tell those who have the ears to hear about their "Salvation Package," which through the death, burial, and resurrection of Christ has been given to those have confused with their mouths that Jesus is Lord and believe in their hearts that God raise Jesus Christ from the dead--Begin a first fruit of His kind [Romans 10:9 NKJV; 1 Corinthians 15:23]. I currently teach on the subjects of the Healing Power of God through Jesus Christ's atonement, How to pray to God correctly ~ Answered Prayer Guaranteed, and soon Christ In Technology. Books soon to follow. A Happy husband to my beloved Mia.

Updated on June 04, 2022

Comments

  • Louis Preston Thornton III
    Louis Preston Thornton III almost 2 years

    I am doing a lab setup of EKS/Kubectl and after the completion cluster build, I run the following:

    > 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.

  • Louis Preston Thornton III
    Louis Preston Thornton III over 4 years
    On the money! Thank you for the assist.