How To Install Kubectl on Ubuntu 22.04? (Step-by-Step Kubectl Installation Guide)

Kubectl is a command-line interface (CLI) tool designed to manage Kubernetes clusters efficiently. It helps manage and control various Kubernetes resources. With Kubectl, users can deploy applications, inspect and modify cluster resources, scale deployments, and troubleshoot issues that may arise. Kubectl acts as a powerful bridge between users and their Kubernetes clusters, simplifying the process of issuing commands and retrieving information.

If you don’t know how to install Kubectl on Ubuntu 22.04, this Kubetcl installation guide will provide step-by-step instructions. By following this guide, you'll be able to successfully install Kubectl on your Ubuntu 22.04 system, enabling you to interact with Kubernetes clusters and execute commands effectively.

Kubectl Installation on Ubuntu 22.04

You can install Kubectl on Ubuntu 22.04 using three different methods that we will explain in this guide:

Method 01: Install Kubectl on Ubuntu Using Apt Package Manager

One method to install Kubectl on Ubuntu 22.04 is using the apt package manager. This method allows you to easily update and manage the Kubectl packages along with all their dependencies.

Step 1: Adding Kubernetes Repository's GPG Key

First, download Kubectl’s GPG key for the Kubernetes repository and add it to your system. Execute the following command in your terminal:

$ curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg

This command downloads the GPG key, converts it to a binary format, and saves it as a keyring file. The keyring file is important for verifying the authenticity of packages from the Kubernetes repository.

Step 2: Adding the Kubernetes Repository to System Sources

Create a repository entry for Kubernetes packages to let apt fetch and install them. Execute the following command in your terminal:

$ echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

Step 3: Updating System Packages

After adding the repository, update the system's package list using the following command:

$ sudo apt update

Step 4: Kubectl Installation Using Apt

Finally, install Kubectl on Ubuntu 22.04 using the apt package manager with the following command:

$ sudo apt install kubectl

This command installs Kubectl along with its dependencies, making it ready for use on your Ubuntu 22.04 system.

Step 5: Verify Installation

Confirm the successful installation of Kubectl by running the following command:

$ kubectl version --output=yaml

This command will display details about the installed version of Kubectl in YAML format, confirming that it's properly installed and available for use.

Method 02: Install Kubectl Binary Using Curl 

This method will download Kubectl’s binary manually from the official Kubernetes repository using the curl command. It's a suitable option if you have specific preferences for the Kubectl version you want to use, or if your system lacks traditional package managers.

Step 1: Download Kubectl Binary

To start Kubectl installation on Ubuntu, first, you will download Kubectl’s binary from the official Kubernetes release repository. Open your terminal and run the following command:

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

The above command will download Kubectl's latest stable binary on your system. If you want a specific Kubectl version, you can adjust the URL accordingly.

Step 2: Set Execution Permissions for the Kubectl Binary

Once the binary is downloaded, make it executable by using the following command:

$ chmod +x kubectl

Step 3: Move the Kubectl Binary to a Directory in the System's PATH

To make Kubectl accessible from any location in the terminal, move the binary to a directory listed in the system's PATH environment variable. Execute the following command:

$ sudo mv kubectl /usr/local/bin

The above command moves the Kubectl binary to the /usr/local/bin directory, which is commonly included in the PATH.

Method 03: Install Kubectl on Ubuntu Using Snap Package Manager

An alternative method for Kubectl installation on Ubuntu 22.04 is using the Snap package manager. This is quite a simple and easy process to install Kubectl on your Ubuntu system. Perform the following two steps to install Kubectl on Ubuntu 22.04 using Snap:

Step 1: Update System Packages

First, ensure your system packages are up to date by running the following command:

$ sudo apt update

Step 2: Install Kubectl With Snap

Use the Snap package manager for Kubectl installation on the Ubuntu 22.04 system by executing this command:

$ sudo snap install kubectl --classic

Conclusion

In this article, we demonstrated how to install Kubectl on the Ubuntu 22.04 Linux distribution. We also showed you how you can download Kubectl’s binary using the Curl command and install it on your system. If you are using a Linux VPS server, using the above steps, you can easily install Kubectl on your server. To explore Kubernetes (Kubectl commands) more, you can visit its official documentation.



Items from an article
  • KVM NVMe VPS 12 GB
    • Country: Singapore
    • CPU 6 x Epyc Core
    • RAM 12 GB
    • HDD 140GB NVMe
    • BANDWIDTH 1 Gbps port
    • IPv4 / IPv6
    € 60/month
    60/month
  • KVM NVMe VPS 2 GB
    • Country: Singapore
    • CPU 2 x Epyc Core
    • RAM 2 GB
    • HDD NVMe : 30GB
    • BANDWIDTH 1 Gbps port
    • IPv4 / IPv6
    € 17/month
    17/month
  • KVM NVMe VPS 4 GB
    • Country: Singapore
    • CPU 2 x Epyc Core
    • RAM 4 GB
    • HDD NVMe : 50GB
    • BANDWIDTH 1 Gbps port
    • IPv4 / IPv6
    € 22/month
    22/month
  • KVM NVMe VPS 8 GB
    • Country: Singapore
    • CPU 4 x Epyc Core
    • RAM 8 GB
    • HDD NVMe : 80GB
    • BANDWIDTH 1 Gbps port
    • IPv4 / IPv6
    € 34/month
    34/month
Blog company: