Kubectl is a powerful command-line tool that helps the developers and administrators to deploy, monitor, manage or scale the application in a containerized environment. Having Kubectl installed on the Ubuntu machines helps the Devops engineers or developers to effectively communicate with different clusters via one-line commands. So, if you are wondering about the installation of the kubectl on Ubuntu 24.04, you are at the right place.
How to Install Kubectl on Ubuntu 24.04?
There are three different methods for installing Kubectl on Ubuntu 24.04. Such methods involves different command utilities, built-in packet managers or third-party packet managers. The methods are given as follows:
- Snap Packet Manager
- Apt Package Manager
- Curl Command Utility
How to Install Kubectl Using Snap Packet Manager?
Snap is an external packet manager that provides different packages for downloading, installing or modifying for Ubuntu distributions. This packet manager is not provided as default in Ubuntu and needs to be separately installed. The following steps provides a practical demonstration of installing the Kubectl Using the Snap packet manager.
Step 1: Update Repository
Before installing the Kubectl on Ubuntu 24.04, update the local package repository using the following command to fetch the latest packages:
sudo apt update
Step 2: Install Snap Dameon
The snap daemon is not pre-installed on the Ubuntu 24.04. Therefore, to install the kubetctl using the snap daemon, first install the snap package manager using the following command:
sudo apt install snapd
Step 3: Install Kubectl
Once the snap package manager is installed, use the following command to install the Kubestcl on Ubuntu 24.04 in the “classic” mode. The classic mode offers smooth installation of the kubectl with the global access to it functionality throughout the system:
sudo snap install kubectl --classic
Step 3: Verify the Installation
Next, we will verify if the kubectl has been successfully installed on the system. For this purpose, use the following command that will return the version of the Kubectl installed on Ubuntu 24.04:
sudo kubectl version --client
How to Uninstall Kubectl on Ubuntu 24.04 Using Snap Packet Manager?
Similarly, to uninstall the Kubectl on Ubuntu 24.04 using the Snap Packet Manger, the steps are given as follows:
Step 1: Uninstall Kubectl
Provide the following command to the terminal to uninstall the Kubectl Using the Snap Packet Manager:
sudo snap remove kubectl
Step 2: Verify the Uninstallation
After uninstalling the kubectl from the Ubuntu 24.04, verify the process using the following command:
sudo kubectl version --client
How to Install kubectl on Ubuntu 24.04 Using Apt Package Manager?
The Apt is a local package manager that is provided as default by various Linux distributions such as Ubunut. Apt simplifies the process of downloading, installing or working with different packages required for various operations. To install Kubectl on Ubuntu 24.04, Apt is another method for it as shown by the steps below:
Step 1: Update Apt Repository
The first step in installing the Kubectl on Ubuntu 24.04 using the Apt package manager is to update the local package repository. For this purpose, provide the following command to the terminal:
sudo apt-get update
Step 2: Install the Curl Command
The curl command is not provided by default in Ubuntu 24.04. Therefore, make the necessary installation such as “apt-transport-https”, “ca-certificate” and “curl” via the following command. This will help in securely accessing the HTTPS repositories using the curl command:
sudo apt-get install -y apt-transport-https ca-certificates curl
Step 3: Download Kubectl Using Curl
Once the curl command-utitly is installed on the system, use the following URL to download the GPG key for downloading the Kubectl. Save the downloaded file to the “/etc/apt/keyrings/kubernetes-apt-keyring.gpg” locatio. This downloading of the GPG key is important as it verifies the downloading and installation of the Kubectl from the Kubernetes repository:
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Step 4: Add the Repository to the Apt Package Manager
The following command adds the Kubernetes repository to the system local package source. This will add the GPG key to the “/etc/apt/sources.list.d/kubernetes.list” directory from where the local package will fetch this URL to install kubectl on Ubuntu 24.04:
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Step 4: Update the Local Package Manager
Again, update the local package manager repository by using the following command to update and save the changes:
sudo apt-get update
Step 5: Install Kubectl
Now, install the kubectl on the system using the following command with a flag -y that refers to “yes”:
sudo apt-get install -y kubectl
Step 6: Verify the Installation
The following command provides detailed information about the client version of the kubectl installed on the Ubuntu 24.04. Use the following command to verify the installation:
kubectl version --client --output=yaml
How to Uninstall Kubectl on Ubuntu 24.04 Using Apt Package Manager?
To uninstall the Kubectl from Ububutu 24.04, the steps are given as follows:
Step 1: Remove Kubectl
Provide the following command to the terminal to uninstall all the dependencies and associated files of the kubectl for a complete uninstallation:
sudo apt autoremove kubectl
Step 2: Verify the Uninstallation
To verify if the kubectl has been uninstalled, use the following command in the terminal:
kubectl version --client --output=yaml
How to Install Kubectl on Ubuntu 24.04 Using Curl Command-Utility?
The curl command utility is used for data transfer via different network protocol i.e., HTTP, HTTPs, FTP, etc. The curl command used with the URL helps the developers in installing the specified package in Ubuntu 24.04. The following steps are used to install the Kubectl on Ubuntu 24.04.
Step 1: Install Curl Command
First install the curl command from the Apt repository using the following command. Provide the password for the currently logged-in user to begin installation:
sudo apt install curl
Step 2: Architecture Type
There are different commands available for installing the Kubectl on Ububtu 24.04 based on the architecture of the system. To determine the architecture of your system, use the following command in terminal:
lscpu
Step 3: Download Kubectl
After determining the architecture of your system, use the appropriate command to install the Kubectl on the system. The following command downloads and installs the stable version of kubectl using the curl command utility:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
Step 4: Modify Permissions
After downloading the kubectl, update the permission for the file “kubectl” to the executable using the flag “+x”:
chmod +x kubectl
The following command lists the detailed information about the kubectl including the permsisions, time of downloading, etc.
ls -al kubectl
Step 5: Move File
Use the following command to move the file to the “/usr/local/bin” location with the administrative privileges:
sudo mv kubectl /usr/local/bin
That is all from installing kubectl on Ubuntu 24.04.
Conclusion
Installing the Kubectl on Ubuntu distributions provides an easy way for deploying and managing different applications inside various clusters. The Kubectl or Kubernetes control is widely practiced by various cloud practitioners and developers for working with the clusters. For installing the Kubectl on Ubuntu 24.04, you can use Snap, Apt package manager or curl command as shown in this guide. Following the steps mentioned in this guide will help you to easily install the Kubectl on Ubuntu 24.04.