Cyberithub

How to Install kubectl on Ubuntu 22.04 LTS (Jammy Jellyfish)

Advertisements

In this article, we will see how to install kubectl on Ubuntu 22.04 LTS (Jammy Jellyfish). kubectl is command line tool provided by Kubernetes for communicating with cluster's control plane using Kubernetes API. Kubectl identifies the cluster configuration from a file called config in the $HOME/.kube directory. You can also provide the config file details by setting either KUBECONFIG environment variable or by setting --kubeconfig flag.

kubectl utility can be used for performing various tasks on k8s cluster such as for deploying applications, inspect and manage cluster resources and for checking the logs. It is also very easy to install and use in almost all the famous platforms. Here we will see the steps to install kubectl on Ubuntu 22.04 LTS Server.

 

How to Install kubectl on Ubuntu 22.04 LTS (Jammy Jellyfish)

How to Install kubectl on Ubuntu 22.04 LTS (Jammy Jellyfish)

Also Read: How to Install traceroute command on Ubuntu 22.04 LTS (Jammy Jellyfish)

Step 1: Prerequisites

a) You should have a running Ubuntu 22.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have snap utility available in your System.

 

Step 2: Update Your Server

In the very first step, you can choose to install all the latest available updates from default Ubuntu repo by using sudo apt update && sudo apt upgrade command as shown below. This will sync all your installed packages to the latest available version.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
Hit:1 http://in.archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:3 http://security.ubuntu.com/ubuntu jammy-security InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease
Hit:5 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:6 https://artifacts.elastic.co/packages/8.x/apt stable InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
1 package can be upgraded. Run 'apt list --upgradable' to see it.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
ubuntu-drivers-common
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

 

Step 3: Check Snap Package

Since we are going to install kubectl as snap package, it is important to check and verify all the information about the snap package before installation using snap info kubectl command as shown below. You will see some of the important information such as publisher, store-url, license, description etc  on the output.

cyberithub@ubuntu:~$ snap info kubectl
name: kubectl
summary: Command line client for controlling a Kubernetes cluster.
publisher: Canonical**
store-url: https://snapcraft.io/kubectl
contact: https://www.ubuntu.com/kubernetes
license: Apache-2.0
description: |
kubectl is a command line client for running commands against Kubernetes
clusters.

For more information about kubectl, including syntax, descriptions of command operations, and
common examples, see the [overview](https://kubernetes.io/docs/reference/kubectl/overview/). For
details about each command, including all the supported flags and subcommands, see the [kubectl
reference
documentation](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands/).
snap-id: ZgG2URycDgvxSVskfoZxn44uaRMw0iwe
.........................................................

 

Step 4: Install Kubectl

In the next step, you can install kubectl utility as a snap package from snap store using sudo snap install kubectl --classic command as shown below.

cyberithub@ubuntu:~$ sudo snap install kubectl --classic
kubectl 1.27.3 from Canonical** installed

 

Step 5: Check Version

After successful installation, you can verify the installed version by running kubectl version --output=yaml command as shown below.

cyberithub@ubuntu:~$ kubectl version --output=yaml
clientVersion:
  buildDate: "2023-06-15T02:15:11Z"
  compiler: gc
  gitCommit: 25b4e43193bcda6c7328a6d147b1fb73a33f1598
  gitTreeState: clean
  gitVersion: v1.27.3
  goVersion: go1.20.5
  major: "1"
  minor: "27"
  platform: linux/amd64
kustomizeVersion: v5.0.1

 

Step 6: Using Kubectl

Now that kubectl utility is installed, it is time to use against the Kubernetes cluster. For example, to check the list of nodes, you can run kubectl get nodes command as shown below.

cyberithub@ubuntu:~$ kubectl get nodes
NAME    STATUS  ROLES           AGE   VERSION
ubuntu  Ready   control-plane   107s  v1.27.2
node    Ready   <none>          12s   v1.27.2

Similarly, to check the list of pods you can use kubectl get pods command as shown below.

cyberithub@ubuntu:~$ kubectl get pods
NAME                        READY  STATUS   RESTARTS  AGE
app-hcm-cbdccf466-k2f8x     1/1    Running  0         78s
app-fscm-cbdccf466-l9xmt    1/1    Running  0         78s
app-portal-cbdccf466-r2zw5  1/1    Running  0         78s

 

Step 7: Uninstall Kubectl

Once you are done using kubectl utility, you can choose to uninstall it from your system by using sudo snap remove kubectl command as shown below.

cyberithub@ubuntu:~$ sudo snap remove kubectl
kubectl removed

Leave a Comment