How to install Kubectl on Ubuntu 22.04

Estimated reading: 4 minutes 473 views

Do you want to install Kubernetes’ command-line tool Kubectl on Ubuntu 22.04 but are unsure how?

This guide will show you how to install Kubectl on Ubuntu 22.04, which will enable you to interact with or execute commands on Kubernetes clusters. By the end of this guide, you should have Kubectl installed on your system.

What is Kubectl?

Before going on to how to install Kubectl on your Ubuntu system, you need to understand what it is and why it is required. Kubectl is a command-line interface (CLI) tool for interacting with Kubernetes clusters. It enables efficient control and management of Kubernetes resources.

With Kubectl, you can deploy applications, inspect and update cluster resources at will, scale deployments, and even troubleshoot issues that surface. Consider Kubectl your bridge, seamlessly connecting you to your Kubernetes cluster, making it easy to issue commands and retrieve information.

Prerequisites

  • Basic knowledge of the Linux command-line interface (CLI)
  • Ubuntu 22.04 server

Install Kubectl on Ubuntu 22.04

In this guide, we’ll explore three common ways of installing Kubectl on your Ubuntu 22.04 system: installing the Kubectl binary using curl, the apt package manager, and the snap package manager.

Method 1 – Install Kubectl binary using curl

This method involves manually downloading a release of the Kubectl binary from the official Kubernetes repository using the curl command. This method is suitable if you prefer a specific version of Kubectl or need to install Kubectl on a system where traditional package managers are unavailable.

Step 1 – Download the Kubectl binary

First, you need to download the Kubectl binary from the official Kubernetes release repository. To do this, run the following command in your terminal:

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

download-kubectl-binary

This will download the latest stable Kubectl binary from the repository. If you would like to download a specific version instead, you can specify the version in the download URL.

Step 2 – Make the Kubectl binary executable

Next, you need to make the downloaded binary executable by running the following command:

chmod +x kubectl

Step 3 – Move Kubectl binary to PATH

Run the following command to move the binary to a directory included in the system’s PATH environment variable:

mv kubectl /usr/local/bin

add-kubectl-to-path

This will make Kubectl accessible from anywhere in the terminal.

Method 2 – Install Kubectl using apt

Another method to install Kubectl on Ubuntu 22.04 is by using the apt package manager. With this method, you can easily update Kubectl and manage its dependencies.

Step 1 – Add Kubernetes repository’s GPG (GNU Privacy Guard) key

First, download the GPG key for the Kubernetes repository by running:

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

add-entry-for-kubernetes-packages

Running this command will download the GPG key, convert it to a binary format, and save it as a GPG keyring file. This keyring file is used to verify the authenticity of the packages, ensuring the genuineness of every package you install from the Kubernetes repository.

Step 2 – Add the Kubernetes repository to your system’s sources.list

Next, create a repository entry for the Kubernetes packages by executing the following in the terminal:

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

add-entry-for-kubernetes-packages

This repository entry will be used by apt to fetch and install packages from the Kubernetes repository.

Step 3 – Update system packages

After adding the repository, update the system packages:

apt-get update

Step 4 – Install Kubectl using the apt package manager

Now, install Kubectl using apt by running the following command:

apt install kubectl

install-kubectl-using-apt

Method 3 – Install Kubectl using Snap

Snap is another package manager that can be used to install Kubectl on Ubuntu 22.04. This method is suitable if you prefer a simple installation process.

Step 1 – Update system packages

Run the following command to update the system packages:

 apt-get update

Step 2 – Install Kubectl

Next, to install Kubectl using Snap, run the command below:

apt install snapd
snap install kubectl --classic

Verify Kubectl Installation

You can verify the Kubectl installation by running the following code in the terminal:

kubectl version --output=yaml

confirm-installation

This will display information about the installed Kubectl in YAML format.

Conclusion

You’ve learned three ways of installing Kubectl on Ubuntu 22.04, and based on your preference, you can decide to use any of them. With Kubectl up and running in your system, you can go on to explore its capabilities by going through its documentation.

Share this Doc

How to install Kubectl on Ubuntu 22.04

Or copy link

CONTENTS