Introduction
The kubectl
tool is the official Kubernetes CLI. The kubectl
command allows you to run commands against your Kubernetes clusters. You can use kubectl
to deploy applications, inspect and manage cluster resources, view logs, and more. This article explains the steps to install kubectl on an Ubuntu machine. However, the steps apply to a majority of Linux machines.
Estimated reading time: 3 minutes
Table of contents
Before installing kubectl
Always install a version of kubectl
that is within one minor version difference of your cluster. For example, if your Kubernetes cluster is running 1.28, then you can install either of 1.27, 1.28 or 1.29 versions of kubectl
.
The easiest way to install kubectl is to download the latest release from the Kubernetes repository. First, identify whether you are running an x86_64 or arm64 architecture system. If you already know your system’s architecture, skip to the next section.
To identify your computer’s architecture, run:
$ uname -m
Example output:
daddy@5c1f1412bd9f:~$ uname -m
x86_64
daddy@5c1f1412bd9f:~$
Installing the latest stable version of kubectl
Let’s look at the easiest way to install the latest and stable version of kubectl
. We assume you should know if you are running an x86_64 or an arm64 computer.
Download the latest binary
If you are running an x86_64 computer, run:
$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
Alternatively, if you are running an arm64 computer, run:
$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"
Installing a specific version of kubectl
If you are looking to install a specific version of kubectl
, then you can replace the $(curl -L -s https://dl.k8s.io/release/stable.txt)
portion of the command with the version you are trying to install. You can get a list of supported versions of Kubernetes and their URLs from downloadkubernetes.com.
Example:
$ curl -LO "https://dl.k8s.io/release/v1.28.4/bin/linux/arm64/kubectl"
Verify the checksum of the binary (optional)
For x86_64 computers, run:
$ echo "$(curl -L -s https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256) kubectl" | sha256sum --check
For arm64 computers, run:
$ echo "$(curl -L -s https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl.sha256) kubectl" | sha256sum --check
If the binary is valid, and the checksum passes, then the output is:
kubectl: OK
If it fails, then sha256 exits with a FAILEd message similar to:
kubectl: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
Installing kubectl
Run the following command to install kubectl
on Ubuntu:
$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
If you do not have root access on your system, you can still use the binary you downloaded by adding execute permissions to it. For example:
chmod +x kubectl
mkdir -p ~/.apps/bin
mv ./kubectl ~/.apps/bin/kubectl
# and then append (or prepend) ~/.apps/bin to $PATH
Test your installation
Test your installation by running the version
command. If the installation was successful, you should see an output that prints the kubectl version.
$ kubectl version --client --output=yaml
For example:
root@5c1f1412bd9f:~# kubectl version --client -o yaml
clientVersion:
buildDate: "2023-12-13T08:51:44Z"
compiler: gc
gitCommit: 3f7a50f38688eb332e2a1b013678c6435d539ae6
gitTreeState: clean
gitVersion: v1.29.0
goVersion: go1.21.5
major: "1"
minor: "29"
platform: linux/arm64
kustomizeVersion: v5.0.4-0.20230601165947-6ce0bf390ce3
Installation using the native package managers
It is also possible to install kubectl on supported platforms with the native package managers such as apt and yum.
Installing kubectl on Ubuntu and other Debian-based systems
Update the apt
package index and install the required packages from the Kubernetes apt
repository:
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
Download the public signing key for the Kubernetes package repositories. This key will be the same for all versions, so you can ignore the version in the URL.
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Add the relevant Kubernetes apt repository, and if you want to install a version other than v1.29, substitute v1.29 with the minor version you want in the following command:
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
Update the apt
package index and install kubectl:
sudo apt-get update
sudo apt-get install -y kubectl
Installing kubectl on CentOS and Redhat-based systems
Add the Kubernetes yum
repository, and if you want to install a version other than v1.29, substitute v1.29 with the minor version you want in the following command:
# This will overwrite any existing configuration in /etc/yum.repos.d/kubernetes.repo
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
EOF
Install kubectl using yum
:
sudo yum install -y kubectl
References
- Install and Set Up kubectl on Linux
- Download Kubernetes
- Kubernetes Release Cycle
- Kubernetes Release History
Read Also:
Hi there, You have done a great job. I’ll certainly digg it
and personally recommend to my friends. I am confident
they will be benefited from this site. https://www.waste-ndc.pro/community/profile/tressa79906983/
Great article and right to the point. I am not sure if this is
actually the best place to ask but do you folks have any thoughts on where to get some professional writers?
Thx 🙂 Escape rooms hub