Install and Set Up kubectl on Linux
Last Updated :
08 Jan, 2024
Kubectl, short for Kubernetes Control, is a powerful command-line tool that facilitates interaction with Kubernetes clusters. As a fundamental component of the Kubernetes ecosystem, kubectl allows users to deploy, manage, and troubleshoot applications within containerized environments. Installing and setting up kubectl on a Linux system is crucial for administrators and developers looking to harness the full potential of Kubernetes orchestration. This process involves downloading the kubectl binary, configuring it for cluster access, and ensuring seamless communication with the Kubernetes API server. Once installed, kubectl empowers users to efficiently control and coordinate containerized applications within Kubernetes clusters, enhancing the scalability, resilience, and manageability of their distributed systems.
What is Kubernetes?
Kubernetes is an open-source platform that manages and clusters Docker containers. Kubernetes (also called Container Orchestration Tool) can be seen as a tool for Container Management that helps with automated deployment, load balancing, scaling, and descaling of containers because it offers healing by automatically restarting containers that fail and rescheduling them if their hosts die. This ability improves a particular application’s availability when deployed using Kubernetes.
What is Kubectl?
Kubectl is a command line utility that can run commands and perform different operations like creating and deleting resources and enlisting the resources inside a Kubernetes cluster. This tool is provided and maintained by Kubernetes itself. To start using Kubectl, we must first install it on our system.
How to install Kubectl on Linux?
We can install Kubectl on the Linux operating system using any of the following three methods:
Open a terminal to install using one of the above methods.
Method 1: Using the curl command
Step 1: Finding the System's CPU architecture
Firstly, we need to use the lscpu command to find the CPU's architecture.
lscpu
Running "lscpu" commandStep 2: Download the Kubectl Binary
Now, we will download the latest Kubectl binary using curl for a particular CPU architecture.
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"
- For x86-64 based systems:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
Download Kubectl BinaryStep 3: Validating the Downloaded Binary File
After downloading the Binary file, we can validate it using the commands below. Firstly, download the Checksum file using the below command.
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl.sha256"
- For x86-64 based systems:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
Download Checksum FileOnce the checksum file is downloaded, we will perform validation of the kubectl binary using the downloaded checksum file
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
Validation using ChecksumIf the above command outputs "OK", then it means you installed the correct kubectl binary file.
Step 4: Making Binary File Executable
Now, we can make the file executable by using the chmod command as below.
chmod +x kubectl
Making Binary File ExecutableStep 5: Installing Kubectl
Once the binary file is made executable, we can install the kubectl using sudo or root user.
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Installing KubectlStep 6: Verifying Installation
After successfully installing Kubectl, we can verify that the Kubectl client is installed correctly by executing the command below.
kubectl version --client
Verifying InstallationMethod 2: Using the apt package manager
Step 1: Updating System
The command "sudo apt-get update" in Linux initiates the update process for package information, fetching the latest metadata from configured repositories. This ensures the system has the most recent package details before proceeding with software installations or upgrades.
sudo apt-get update
Update apt indexStep 2: Adding Kubernetes package repository's public signing key
Download the public signing key for the Kubernetes package repositories.
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Downloading public signing key for Kubernetes repositoryStep 3: Add the Kubernetes apt repository
The below command adds the Kubernetes apt repository to the system's package sources, enabling the installation of Kubernetes-related packages. The repository URL specifies the version (v1.29 in this case), and the GPG key is used for package verification.
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Adding Kubernetes apt repositoryStep 4: Updating System
After adding Kubernetes to the apt repository, we need to update the system repositories again using the apt manager.
sudo apt-get update
Updating SystemStep 5: Installing kubectl
The below command installs the Kubernetes command-line tool, kubectl, with the "-y" flag automatically confirming any prompts. This tool is essential for interacting with Kubernetes clusters and managing containerized applications.
sudo apt-get install -y kubectl
Installing kubectlStep 6: Verifying Installation
Ensure that the Kubectl client is installed correctly.
kubectl version --client
Verifying InstallationMethod 3: Using Snap package manager
Step 1: Updating System
Firstly, update the repositories using the apt manager. Execute the below command to update.
sudo apt update
Updating SystemStep 2: Install kubectl using snap
The below command installs kubectl, the Kubernetes command-line tool, using the Snap package manager with the "--classic" flag, allowing for a confined but classic Snap package installation.
sudo snap install kubectl --classic
Install kubectl using snap.Step 3: Verifying Installation
Ensure that the Kubectl client is installed correctly.
kubectl version --client
Verifying InstallationNow, once you have successfully installed the kubectl command line utility, you can start using the kubectl tool. You can try out the different Kubectl commands for creating and managing clusters here.
Conclusion
In conclusion, Kubernetes is an open-source platform that manages and clusters Docker containers. Kubectl is a command line utility that can run commands and perform different operations like creating and deleting resources and enlisting the resources inside a Kubernetes cluster. In this article, we have seen three different methods of installing Kubectl on Linux-based systems.
Similar Reads
How to Install Kotlin on Linux?
Kotlin is a programming language introduced by JetBrains in 2011, the official designer of the most intelligent Java IDE, named Intellij IDEA. This is a strongly statically typed general-purpose programming language that runs on JVM. In 2017, Kotlin is sponsored by Google, announced as one of the of
2 min read
How to Install Keras on Linux?
Keras is an open-source software library that offers a Python interface for ANN (artificial neural networks). It acts as an interface for the TensorFlow library. It offers consistent & simple APIs, minimizes the number of user actions required for common use cases, and provides clear & actio
2 min read
How to Install Jekyll on Linux?
Jekyll is software used for creating websites. It can create websites more dynamically. Jekyll is useful nowadays. It can convert simply written text files into website documentation. It is simple to use. There is no database required for using Jekyll. It is very easy to use. Jekyll is platform-inde
2 min read
How to Install Git on Kali Linux
Git is an important version control system that is renowned for its reliability and cooperation capabilities. The process of installing Git on Kali Linux is straightforward and efficient, guaranteeing that it works seamlessly with your development process. We'll carefully walk you through each step
7 min read
How to Install Scikit-Learn on Linux?
In this article, we are going to see how to install Scikit-Learn on Linux. Scikit-Learn is a python open source library for predictive data analysis. It is built on NumPy, SciPy, and matplotlib. It is written in Python, Cython, C, and C++ language. It is available for Linux, Unix, Windows, and Mac.
2 min read
How to Install Katoolin on Linux Mint?
If you're looking to install Katoolin on Linux Mint, this guide will help you set it up step by step. Katoolin is a powerful tool that allows users to install Kali tools on non-Kali distributions, such as Linux Mint. By following the instructions in this Katoolin installation guide for Linux Mint, y
3 min read
How to Install Python 3 on Kali Linux
Python 3 is a powerful and versatile programming language widely used for various tasks, from web development to data science, security automation, and AI and ML. Recent versions of Kali Linux come with Python 3 pre-installed. For some reason if you want a different version than the one already inst
3 min read
How to install Kloxo-MR in Linux
Kloxo-MR is a free web hosting panel available for Linux distributions. The name of the Lxadmin earlier knew it. But in 2017, The Lxadmin name was changed to the name Kloxo-MR. As there was some issue with the name. And also, there was a massive response from the user to change the application's nam
7 min read
How to Install Kdenlive in Linux
Kdenlive is a free and open-source video editing software, available for windows, mac, and Linux. It stands for KDE Non-Linear Video Editor. As the name suggests, it is a non-linear video editing software. A non-linear video is the one that lets you edit clips and videos in any order and does not re
3 min read
Tool-X - Hacking Tool Installer in Kali Linux
Tool-X is a free and open-source tool written in python that is available on GitHub. Tool-X is used by security researchers and pen-testers in the early stages of reconnaissance and pen-testing. It is an installer framework for Kali Linux that has approximately 300 tools available on its menu. It wi
2 min read