Installing kubectl - the k8s command line tool
How to install Kubectl
With Civo Academy, Learn how to install Kubectl and how to make Kubectl binary executable.
The first thing that we need to do is download the latest Kubectl binary with curl. Copy the command
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl". We will be using Apple Silicon; that's why it says ARM over here. If you're using Intel, it would be saying AMD. Just copy this and paste it over in your terminal. You can see it's downloading the latest release now.
If you want to download a specific release, you can replace it with the particular version that you want to use. You can also validate the binary, but this step is optional. You can download the checksum file. And it should show Kubectl: OK as an output when we validate it. So let's try to run this.
Making kubectl binary executable
The next thing is that we have to make this Kubectl binary executable. This is because whenever we're running commands like this, they are usually shown in your path variables. So whenever you type some command like Kubectl or the simplest commands like Git, these are all executables that are stored in your path. So the first thing we need to do is make it executable. So we can change the permissions for that and make it executable because it's in our current directory but not in our path. So that is the other step that we need to take.
We need to move this particular file into our system path. For that, copy the command
chmod +x ./kubectl and paste it into the terminal. Then, copy the command and paste the command
sudo mv ./kubectl /usr/local/bin/kubectl into the terminal. Now it's in my particular path. If you want to list your particular path, you can use the command
ls /usr/local/bin | grep "Kubectl". You can see that it's available over here.
We can also echo our path using the command
echo $path. As you can see, my
usr/local/bin is available over here. Whenever I type Kubectl, it will give me this particular green color code over the text. It means this command is valid because I'm using an item. So this particular thing, it's going to search for it in my path, which is here. That's how environment variables work. You will see that it's particularly installed.
We also need to change the owner for this. So we can do that via the command
sudo chown root: /usr/local/bin/kubectl. After this, we have to validate it using the command
kubectl version -client. So now we will see the particular output, and our Kubectl is installed now.
But the output is very ugly and in an unreadable format. Fortunately, in Kubectl, we can use a few different formats for its output. For example, we can use YAML files. So I can use the validate command like
kubectl version --output==yaml. This is a much cleaner way, and it's much more readable. So that was about installing Kubectl, and the next step for us to do is the installation of minikube.