Installing kubectl - the k8s command line tool
Civo Academy - Installing Kubectl - the K8s command line tool
Description
With Civo Academy, Learn how to install Kubectl and how to make Kubectl binary executable.
Downloading Kubectl
The first step in the process is to download the latest Kubectl binary. This can be done using the curl command. Depending on your system's architecture, you'll need to select the appropriate binary. For Apple Silicon, the ARM binary is used, while Intel systems use the AMD binary.
To download the latest release, use the following command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"
If you wish to download a specific release, replace the URL with the version you want to use.
Validating the binary
While this step is optional, it's recommended to validate the binary to ensure its integrity. You can do this by downloading the checksum file and comparing it with the downloaded binary. If the validation is successful, you'll see "Kubectl: OK" as the output.
Making Kubectl binary executable
After downloading and validating the binary, the next step is to make it executable. This is necessary because commands like Kubectl are executables stored in your system's path.
To make the Kubectl binary executable, change its permissions using the following command:
chmod +x ./kubectl
Next, move the executable file into your system path with this command:
sudo mv ./kubectl /usr/local/bin/kubectl
You can verify that Kubectl is in your path by using the command `ls /usr/local/bin | grep "Kubectl"`.
Checking your system path
After moving the Kubectl binary into your system path, you may want to verify that it's correctly placed. You can do this by echoing your path using the command `echo $path`. This will display all the directories listed in your system's PATH environment variable.
If the installation was successful, you should see `usr/local/bin` in the output. This is where the Kubectl binary resides.
Verifying the Kubectl command
To verify that the Kubectl command is recognized by your system, simply type `kubectl` in your terminal. If you're using iTerm, a valid command will be highlighted in green. This indicates that the command is found in your system's PATH and is ready to be executed.
This is how environment variables work. When you type a command, your system searches for it in the directories listed in the PATH variable. If the command is found, it's executed; if not, you'll see a 'command not found' error.
Changing the Owner of the Kubectl Binary
To ensure that the Kubectl binary is correctly owned, you can change the owner using the following command:
sudo chown root: /usr/local/bin/kubectl
Verifying the installation
Once Kubectl is installed and executable, you can validate the installation using the command `kubectl version -client`. If the installation is successful, you'll see the version output.
By default, the output might be in a format that's hard to read. However, Kubectl allows you to change the output format. For example, you can use the YAML format for a cleaner and more readable output:
kubectl version --output=yaml
And that's it! You've successfully installed Kubectl and made it executable. The next step in your Kubernetes journey is the installation of Minikube, which we'll cover in another lesson.
These may also be of interest
Kubectl commands - a comprehensive guide
Get more productive with kubectl, the Kubernetes command-line tool. This guide covers setting up autocompletion, managing contexts and configuration, working with namespaces, troubleshooting pods, and more.
Guides for kubectl
Discover our kubectl tutorials and master interacting with your Kubernetes cluster using the kubectl CLI. Get started with kubectl today!
Deploy your first Kubernetes application through CLI
Deploy your first Kubernetes app with ease using kubectl. This step-by-step guide provides a smooth introduction to cluster configuration, resource definition, deployment, and testing.