Install kubectl in linux

Spread the love

The command-line tool for communicating with Kubernetes clusters is called Kubectl. It lets you create, remove, and update components, inspect cluster resources, and deploy and manage apps on Kubernetes. As of 2024, this guide offers the most up-to-date instructions for installing Kubectl on different Linux distributions.
Install Kubectl on Ubuntu/Debian

To install Kubectl on Ubuntu or Debian-based distributions, follow these steps:

Update Package List and Install Dependencies:

sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl

Download and Add Google Cloud Public Signing Key:

sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

Add Kubernetes APT Repository:

echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

Update Package List and Install Kubectl:

sudo apt-get update
sudo apt-get install -y kubectl

Install Kubectl on CentOS/Fedora/RHEL

For CentOS, Fedora, or RHEL-based distributions, use the following steps:

Create Kubernetes YUM Repository:

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

Install Kubectl:

sudo yum install -y kubectl

Install Kubectl with Snap on Ubuntu

Ubuntu users can also install Kubectl using the Snap package manager:

Install Kubectl via Snap:

sudo snap install kubectl --classic

Verify Installation:

kubectl version --client

Install Kubectl Binary Using Curl

You can manually download and install the Kubectl binary:

Download the Latest Release:

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

Make the Binary Executable:

chmod +x ./kubectl

Move the Binary to Your Path:

sudo mv ./kubectl /usr/local/bin/kubectl

Verify Installation:

kubectl version --client

Conclusion

You can install Kubectl’s most recent version on your Linux system by using these methods. To ensure that Kubectl is prepared to manage your Kubernetes clusters efficiently, select the approach that best fits your environment and follow the instructions. For the most recent information and recommended practices, always refer to the official Kubernetes documentation.

Leave a Comment

PHP Code Snippets Powered By : XYZScripts.com