In this short article, we will learn how to install Kubectl on Ubuntu 22.04 LTS operating system.
Introduction
Kubectl is a powerful command-line tool that serves as the primary interface for interacting with Kubernetes clusters. It allows users to manage, deploy, and troubleshoot applications and resources within Kubernetes environments. In this article, we’ll explore the key features of kubectl, its benefits, and how to effectively use it for managing your Kubernetes clusters.
Key Features of Kubectl
Resource Management: Kubectl enables users to create, update, and delete Kubernetes resources such as pods, services, deployments, and more.
Cluster Interaction: It provides a way to interact with multiple Kubernetes clusters, allowing users to manage resources across various environments.
Configuration Management: Kubectl allows users to manage cluster configuration files, including context, authentication, and namespace settings.
Pod Inspection: Users can inspect pod logs, view pod descriptions, and access terminal sessions within pods.
Rollouts and Updates: Kubectl supports rolling updates and deployments, allowing for seamless application updates without service interruption.
Scaling and Autoscaling: Users can scale resources manually or configure autoscaling based on metrics.
Access and Security: Kubectl helps manage access control through role-based access control (RBAC) and secrets management.
Benefits of Using Kubectl
- Unified Interface: Kubectl provides a standardized way to manage Kubernetes resources, eliminating the need for different tools for various tasks.
- Automation: Automation and scripting can be achieved using kubectl commands, streamlining repetitive tasks.
- Flexibility: Kubectl’s versatility makes it suitable for both beginners and advanced users in managing Kubernetes clusters.
- Efficiency: By interacting with clusters using the command line, users can quickly perform operations without navigating through graphical interfaces.
Benefits of Using Kubectl
- Unified Interface: Kubectl provides a standardized way to manage Kubernetes resources, eliminating the need for different tools for various tasks.
- Automation: Automation and scripting can be achieved using kubectl commands, streamlining repetitive tasks.
- Flexibility: Kubectl’s versatility makes it suitable for both beginners and advanced users in managing Kubernetes clusters.
- Efficiency: By interacting with clusters using the command line, users can quickly perform operations without navigating through graphical interfaces.
How To Install Kubectl on Ubuntu 22.04 Operating System
There are three methods for installing kubectl on the Ubuntu operating system, namely: installing the Kubectl binary using the apt package manager, and the snap package manager and curl.
Prerequisites
Before installing Kuebctl on the system, we must already have :
- Ubuntu 22.04 LTS operating system
- A user with sudo/admin privilege
Install Kubectl Using apt Package Manager
In this section we will install Kubectl by using apt package manager. Here are the step install Kubectl by using this method.
Step 1 – Add Kubernetes repository’s GPG (GNU Privacy Guard) key
Step 2 – Update system packages
Step 3 – Install Kubectl using the apt package manager
Each item will be explained in more detail in the following sub-chapters.
1. Add Kubernetes repository’s GPG (GNU Privacy Guard) key
The first step is to donwlon Kubectl PG key, by submitting command line :
$ curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg [sudo] password for ramansah:
$ 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 deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main
2. Update system packages
After kubectl repository was added, then we will update the system by submitting command line :
$ sudo apt update
3. Install Kubectl using the apt package manager
In this stage, we will install Kubectl by using apt package manage. For this purpose we submi the following command line :
$ sudo apt install kubect
Output :
ramansah@infodiginet:~$ sudo apt install kubectl [sudo] password for ramansah: Reading package lists... Done Building dependency tree... Done Reading state information... Done The following NEW packages will be installed: kubectl 0 upgraded, 1 newly installed, 0 to remove and 170 not upgraded. Need to get 10,3 MB of archives. After this operation, 49,9 MB of additional disk space will be used. Get:1 https://packages.cloud.google.com/apt kubernetes-xenial/main amd64 kubectl amd64 1.28.1-00 [10,3 MB] Fetched 10,3 MB in 8s (1.292 kB/s) Selecting previously unselected package kubectl. (Reading database ... 283141 files and directories currently installed.) Preparing to unpack .../kubectl_1.28.1-00_amd64.deb ... Unpacking kubectl (1.28.1-00) ... Setting up kubectl (1.28.1-00) ...
After installation is completed done, the we will verify it by querying its version.
$ kubectl version --output=yaml
Output :
ramansah@infodiginet:~$ kubectl version --output=yaml clientVersion: buildDate: "2023-08-24T11:23:10Z" compiler: gc gitCommit: 8dc49c4b984b897d423aab4971090e1879eb4f23 gitTreeState: clean gitVersion: v1.28.1 goVersion: go1.20.7 major: "1" minor: "28" platform: linux/amd64 kustomizeVersion: v5.0.4-0.20230601165947-6ce0bf390ce3
So far, we have installed kubectl on Ubuntu 22.04 LTS operating system.
Conclusion
Kubectl is an essential tool for managing Kubernetes clusters, offering a command-line interface to efficiently manage, deploy, and troubleshoot applications and resources. With its flexibility, unified interface, and automation capabilities, kubectl empowers users to interact with Kubernetes clusters effectively, making it a must-have tool for anyone working with container orchestration and cloud-native applications.