How to Install Kubectl on Ubuntu 24.04

Install Kubectl on Ubuntu 24.04

Kubectl is the command-line interface to Kubernetes. This powerful tool empowers you to effortlessly create, manage, and monitor your Kubernetes resources. From deploying and scaling applications to troubleshooting and debugging, Kubectl is your go-to companion. This guide will walk you through the process step-by-step to install Kubectl on Ubuntu 24.04, enabling you to harness the full potential of Kubernetes from your terminal.

How to Install Kubectl on Ubuntu 24.04

To install Kubectl on Ubuntu 24.04, use the below methods:

Method 1: Installing Kubectl on Ubuntu 24.04 Using Snap Store

The quickest way to get Kubectl up and running on Ubuntu 24.04 is through the Snap Store. While this method might not provide the absolute latest version, it offers a near-current one. The store is already part of Ubuntu 24.04. If it’s missing, you can easily re-install it by using the following command:

sudo apt install snapd -y

Kubectl can be installed on Ubuntu 24.04 by utilizing the Snap Store. To begin the installation process, use the below command:

sudo snap install kubectl --classic

sudo snap install kubectl --classic

To successfully install Kubectl on your Ubuntu system using the Snap Store, execute the command below:

kubectl version --client

kubectl version --client

Note: If Kubectl was installed from the Ubuntu Snap Store, it can be easily removed by running the following command:

sudo snap remove kubectl

sudo snap remove kubectl

Method 2: Installing Kubectl on Ubuntu 24.04 Using Kubernetes Repository

To install the latest Kubectl release on Ubuntu 24.04, you’ll need to add the official Kubernetes repository to your system and then use the apt package manager. Let’s follow the below steps:

Step 1: Download the GPG Key

The first step is to confirm the legitimacy of the Kubernetes repository. Achieve this by acquiring the public signing or GPG key on your Ubuntu system through the provided command:

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

Step 2: Add Kubernetes Repository

To access the Kubernetes packages, you’ll need to add its repository to Ubuntu. Use this command to do so:

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

Step 3: Update Ubuntu Repository

Update Ubuntu’s package information to reflect the added Kubernetes repository:

sudo apt update

sudo apt update

Step 4: Install Kubectl on Ubuntu

With the repository refreshed, users can proceed for installing Kubectl on the Ubuntu system utilizing the apt package manager:

sudo apt install kubectl -y

sudo apt install kubectl -y

Step 5: Confirm Kubectl Installation

Users can verify that Kubectl is successfully installed from the Ubuntu apt package manager by running the below command:

kubectl version --client

kubectl version --client

Note: If you no longer require Kubectl on your Ubuntu system, you can fully uninstall it and its associated components by executing the following command:

sudo apt autoremove kubectl -y

sudo apt autoremove kubectl -y

Method 3: Installing Kubectl on Ubuntu 24.04 Using Kubectl Binary File

Kubernetes developers provide a downloadable Kubectl binary. This file can be executed on your system to interact with Kubernetes clusters. The following steps outline how to install Kubectl on Ubuntu 24.04 using this method:

Step 1: Download the Kubectl Binary File

To begin, download the Kubectl command-line tool suitable for your AMD64 Ubuntu setup. Use the provided terminal command to retrieve the Kubectl binary file:

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

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

Important: For ARM64, replace amd64 with arm64 in the above command.

Step 2: Validate the Binary (Optional)

To verify the authenticity of your Kubectl binary, you’ll first need to obtain the corresponding checksum file by executing the following command:

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

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

Ensure the downloaded Kubectl binary is authentic by comparing it to the checksum file:

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

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

Receiving an ‘OK’ output as a result of the validation process confirms the integrity of your Kubectl binary file.

Step 3: Make the Kubectl Binary File Executable

Next, you’ll need to make the downloaded Kubectl file executable. To perform this, execute the below chmod command on Ubuntu:

sudo chmod +x kubectl

sudo chmod +x kubectl

Step 4: Move the Kubectl Binary File to the Bin Directory

Next, you’ll need to make the downloaded Kubectl file executable. To do this, run the following chmod command on Ubuntu:

sudo mv kubectl /usr/local/bin

sudo mv kubectl /usr/local/bin

Step 5: Confirm Kubectl Installation

To confirm that Kubectl is installed correctly, please close and reopen your terminal window. Then, use the command below to check its status on your Ubuntu system:

kubectl version --client

kubectl version --client

If you installed Kubectl directly as a binary file, you can remove it by deleting the file from the bin directory. Use this command:

sudo rm /usr/local/bin/kubectl

sudo rm /usr/local/bin/kubectl

Conclusion

Kubectl is a command-line utility essential for managing Kubernetes clusters directly from the terminal. On Ubuntu 24.04, you have multiple options to install it: the straightforward Snap Store using “snap install kubectl –classic” the more involved Kubernetes repository requiring key addition and repository configuration before using “apt install kubectl” or the manual method of downloading the binary from the official Kubernetes website, making it executable, and placing it in the /usr/local/bin directory.