20

I was running kubectl command to deploy my application in the gcloud. But suddenly the kubectl command stopped working. kubectl command is working fine but for everything else it say command not found.

kubectl create bash: kubectl create: command not found

kubectl run bash: kubectl run: command not found

SBGML02586:~ mku01$ kubectl
kubectl controls the Kubernetes cluster manager. 

Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/

Basic Commands (Beginner):
  create         Create a resource from a file or from stdin.
  expose         Take a replication controller, service, deployment or pod and
expose it as a new Kubernetes Service
  run            Run a particular image on the cluster
  set            Set specific features on objects......
Promise Preston
  • 24,334
  • 12
  • 145
  • 143
krmanish007
  • 6,749
  • 16
  • 58
  • 100

5 Answers5

38

I had a similar error when I was setting up Kubernetes on Linux for the first time:

When I try to run the commands:

kubectl cluster-info
kubectl version

I get the error:

-bash: kubectl: command not found

Here's how I fixed it:

Download the latest Kubernetes release with the command:

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"

Make the kubectl binary executable:

chmod +x ./kubectl

Move the binary in to your PATH:

sudo mv ./kubectl /usr/local/bin/kubectl

Test to ensure the version you installed is up-to-date:

kubectl cluster-info
kubectl version

You can read up more about it in the Kubernetes Official Docs: Install and Set Up kubectl

That's all.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
  • 1
    I think its important to mention to new people starting using Kubernetes(like me..) that this comands should be run from a different account than root, with privileges of sudo. In my case I was blocked at the start just because I was running the installation as root. – Ricardo Rivera Nieves Dec 25 '20 at 01:04
  • 1
    Good solution with clear explanation, many thanks – David Robertson Jun 05 '23 at 07:29
9

I got this message while using wsl on windows. kubectl was working but suddenly started showing the same error

/mnt/c/Users/xxxx$ kubectl
kubectl: command not found

The issue was that docker was not started after I had restarted my laptop

:/usr/local/bin$ ls -ltr
total 2548
-rwxr-xr-x 1 root root     221 Sep 18  2020 pip3.8
-rwxr-xr-x 1 root root     221 Sep 18  2020 pip3
-rwxr-xr-x 1 root root     221 Sep 18  2020 pip
-rwxr-xr-x 1 root root     208 Sep 18  2020 wheel
-rwxr-xr-x 1 root root 2592768 Apr  5 10:57 kubectx
lrwxrwxrwx 1 root root      55 May 24 11:22 kubectl -> /mnt/wsl/docker-desktop/cli-tools/usr/local/bin/kubect

It started working once I started my docker application (I use docker-desktop for windows, and I had disabled auto-start on startup)

Ritesh
  • 3,569
  • 2
  • 8
  • 10
5

Homebrew users might fix it with:

brew reinstall kubectl

May need to follow it with:

brew link --overwrite kubernetes-cli
MikeiLL
  • 6,282
  • 5
  • 37
  • 68
  • Had to run `brew unlink kubernetes-cli && brew link kubernetes-cli` instead of `brew link --overwrite kubernetes-cli` but it helped, thanks :) – Andrey Deineko Jul 19 '23 at 07:00
0

Please check your nix config file and add "kubernetes.enable = true;" in tools.

Farjad
  • 19
  • 2
0

kubectl is not available after enabling kubernetes in docker-desktop. Follow these steps to resolve the issue:

First step: Download the latest release with the command:

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

Second step: Download the kubectl checksum file:

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

Validate the kubectl binary against the checksum file:

echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check

If valid, the output is:

kubectl: OK

If the check fails, sha256 exits with nonzero status and prints output similar to:

Note: Download the same version of the binary and checksum.

Third step:

Install kubectl

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

Fourth step:

Test to ensure the version you installed is up-to-date:

kubectl version --client

or use this for detailed view of version:

kubectl version --client --output=yaml    
Paul
  • 1,344
  • 4
  • 19
  • 37