Cyberithub

How to Install kubectl on Ubuntu 20.04 LTS (Focal Fossa)

Advertisements

In this article, I will take you through the steps to install kubectl on Ubuntu 20.04 LTS (Focal Fossa). Kubectl is free and open source Kubernetes command line tool that allows you to run command against Kubernetes Clusters. It can be used to deploy applications, inspect and manage cluster resources, and view logs. More on Kubernetes Official website.

How Kubectl Works

Kubectl works by authenticating with the master server and then performing tasks based on command given. By default, kubectl reads the config file stored in .kube directory under User's home path and then perform specific tasks based on API request against the respective Cluster.

How to Install kubectl on Ubuntu 20.04 LTS (Focal Fossa)

How to Install kubectl on Ubuntu 20.04 LTS (Focal Fossa)

Also Read: How to Setup and Use Atlantis for Terraform Pull Request Automation

Step 1: Prerequisites

a) You should have a running Linux(Ubuntu 20.04 LTS) Server.

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

c) You should have apt or apt-get utility available in your System.

 

Step 2: Update Your Server

Before installing a package, it is always recommended to update your server first with the latest available updates. For that, you can use any available package manager in your System. For example, in our Ubuntu 20.04 LTS system we are using apt-get update command to sync all the packages. If you are using RHEL/CentOS based systems then you can either use yum update or dnf update command for this activity.

Advertisements
root@cyberithub:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:3 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:4 http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu focal InRelease
Get:5 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:6 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Get:7 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [1,669 kB]
Get:9 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,095 B]
Hit:2 https://downloads.apache.org/cassandra/debian 40x InRelease
Get:10 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [620 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages [406 kB]
Get:12 http://in.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [315 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [278 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/main DEP-11 48x48 Icons [60.8 kB]
Get:15 http://in.archive.ubuntu.com/ubuntu focal-updates/main DEP-11 64x64 Icons [98.3 kB]
Get:16 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [14.8 kB]
Get:17 http://in.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [881 kB]
Get:18 http://in.archive.ubuntu.com/ubuntu focal-updates/restricted i386 Packages [24.3 kB]
Get:19 http://in.archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [126 kB]
Get:20 http://in.archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [528 B]

 

Step 3: Install Kubectl

There are multiple ways to install kubectl utility but here we are going to install it from Snap Store as a snap package. You just need to use snap install kubectl --classic command for the installation as shown below.

root@cyberithub:~# snap install kubectl --classic
kubectl 1.23.5 from Canonical* installed

 

Step 4: Check Kubectl Version

Once installed, you can verify the current version by using kubectl version command as shown below.

root@cyberithub:~# kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.5", GitCommit:"c285e781331a3785a7f436042c65c5641ce8a9e9", GitTreeState:"clean", BuildDate:"2022-03-17T03:51:43Z", GoVersion:"go1.17.8", Compiler:"gc", Platform:"linux/amd64"}

 

Step 5: Check all the Available Options

You can also check all the options available with kubectl command using kubectl --help command as shown below.

root@cyberithub:~# kubectl --help
kubectl controls the Kubernetes cluster manager.

Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/

Basic Commands (Beginner):
create Create a resource from a file or from stdin
expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes service
run Run a particular image on the cluster
set Set specific features on objects

Basic Commands (Intermediate):
explain Get documentation for a resource
get Display one or many resources
edit Edit a resource on the server
delete Delete resources by file names, stdin, resources and names, or by resources and label selector

Deploy Commands:
rollout Manage the rollout of a resource
scale Set a new size for a deployment, replica set, or replication controller
autoscale Auto-scale a deployment, replica set, stateful set, or replication controller

 

Step 6: Uninstall Kubectl

To remove kubectl snap package, you need to use snap remove kubectl command as shown below.

root@cyberithub:~# snap remove kubectl
kubectl removed

Leave a Comment