Installing Kubectl

Hello, I am now trying to install Kubectl in my Ubuntu 22.04 version. I installed it successfully a few days ago. But I don’t know why it cannot work now. I always get the error message:

bash: /home/tunyenchiang/.local/bin/kubectl: cannot execute binary file: Exec format error

So now I decide to reinstall Kubectl again. However, when I try the command

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"

I get the following error:

curl: (56) OpenSSL SSL_read: Connection reset by peer, errno 104

Does anyone know how to solve this problem? Or some ways to delete the Kubernated completely. Thank you

It seems like you’re encountering multiple issues while trying to install or reinstall kubectl on your Ubuntu 22.04 system. Let’s troubleshoot this step by step:

  1. Executable Format Error: The error message cannot execute binary file: Exec format error typically occurs when you are trying to run a binary that’s not compatible with your system architecture. It seems you might have downloaded the wrong binary for your system.

  2. Connection Reset Error: The Connection reset by peer error during the curl command suggests a network issue or a problem with the server from which you’re trying to download the kubectl binary.

To address these issues:

  1. Check System Architecture: Ensure you’re downloading the correct binary for your system architecture. Since you’re using Ubuntu 22.04, which is likely to be on “ARM64” architecture, therefore you should download the ARM64 version of kubectl.

  2. Network Issue: The Connection reset by peer error might indicate a temporary network problem. You can try running the curl command again after some time to see if the issue persists.

  3. Clean Installation: If you want to start fresh and reinstall kubectl, you can follow these steps to remove the existing installation and then reinstall it:

    # This commands Deletes the existing kubectl binary
    rm ~/.local/bin/kubectl
    
    # This command will Remove any leftover configuration files (optional)
    rm -rf ~/.kube
    
    # To Reinstall kubectl using the correct command I recommend you to use the following command
    curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl" 
    
    # This command will Make the downloaded binary executable
    chmod +x kubectl
    
    # To Move the binary to a directory in your PATH
    sudo mv kubectl /usr/local/bin/kubectl
    

Try to follow the aforementioned steps and try running kubectl again and I believe it should work now.

I solved the problem. It turned out that my system is x64 instead of arm64. So I cleaned the kubectl first and then followed the instruction in the official website.