Install and Set Up kubectl on Linux
Before you begin
You must use a kubectl version that is within one minor version difference of your cluster. For example, a v1.28 client can communicate with v1.27, v1.28, and v1.29 control planes. Using the latest compatible version of kubectl helps avoid unforeseen issues.
Install kubectl on Linux
The following methods exist for installing kubectl on Linux:
- Install kubectl binary with curl on Linux
- Install using native package management
- Install using other package management
Install kubectl binary with curl on Linux
Download the latest release with the command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"
Note:
To download a specific version, replace the
$(curl -L -s https://dl.k8s.io/release/stable.txt)
portion of the command with the specific version.For example, to download version 1.28.0 on Linux x86-64, type:
curl -LO https://dl.k8s.io/release/v1.28.0/bin/linux/amd64/kubectl
And for Linux ARM64, type:
curl -LO https://dl.k8s.io/release/v1.28.0/bin/linux/arm64/kubectl
Validate the binary (optional)
Download the kubectl checksum file:
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl.sha256"
Validate the kubectl binary against the checksum file:
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
If valid, the output is:
kubectl: OK
If the check fails,
sha256
exits with nonzero status and prints output similar to:kubectl: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
Note: Download the same version of the binary and checksum.
Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Note:
If you do not have root access on the target system, you can still install kubectl to the
~/.local/bin
directory:chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin/kubectl
# and then append (or prepend) ~/.local/bin to $PATH
Test to ensure the version you installed is up-to-date:
kubectl version --client
Or use this for detailed view of version:
kubectl version --client --output=yaml
Install using native package management
Update the
apt
package index and install packages needed to use the Kubernetesapt
repository:sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl
Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Add the appropriate Kubernetes
apt
repository. If you want to use Kubernetes version different than v1.28, replace v1.28 with the desired minor version in the command below:# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Note: To upgrade kubectl to another minor release, you’ll need to bump the version in /etc/apt/sources.list.d/kubernetes.list
before running apt-get update
and apt-get upgrade
. This procedure is described in more detail in Changing The Kubernetes Package Repository.
Update
apt
package index, then install kubectl:sudo apt-get update
sudo apt-get install -y kubectl
Note: In releases older than Debian 12 and Ubuntu 22.04, /etc/apt/keyrings
does not exist by default, and can be created using sudo mkdir -m 755 /etc/apt/keyrings
- Add the Kubernetes
yum
repository. If you want to use Kubernetes version different than v1.28, replace v1.28 with the desired minor version in the command below.
# This overwrites 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.28/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.28/rpm/repodata/repomd.xml.key
EOF
Note: To upgrade kubectl to another minor release, you’ll need to bump the version in /etc/yum.repos.d/kubernetes.repo
before running yum update
. This procedure is described in more detail in Changing The Kubernetes Package Repository.
- Install kubectl using
yum
:
sudo yum install -y kubectl