⎈ k8s knowledge compiler

Install and Set Up kubectl on Linux [page]deterministic

taskscliapi

##

You must use a kubectl version that is within one minor version difference of your cluster. For example, a v client can communicate with v, v, and v 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-kubectl-binary-with-curl-on-linux)
  • [Install using native package management](#install-using-native-package-management)
  • [Install using other package management](#install-using-other-package-management)

### Install kubectl binary with curl on Linux

1. 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 on Linux x86-64, type:

```bash curl -LO https://dl.k8s.io/release/v/bin/linux/amd64/kubectl ```

And for Linux ARM64, type:

```bash curl -LO https://dl.k8s.io/release/v/bin/linux/arm64/kubectl ```

1. Validate the binary (optional)

Download the kubectl checksum file:

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

Validate the kubectl binary against the checksum file:

```bash echo "$(cat kubectl.sha256) kubectl" | sha256sum --check ```

If valid, the output is:

```console kubectl: OK ```

If the check fails, `sha256` exits with nonzero status and prints output similar to:

```console kubectl: FAILED sha256sum: WARNING: 1 computed checksum did NOT match ```

> Note: Download the same version of the binary and checksum.

1. Install kubectl

```bash 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:

```bash chmod +x kubectl mkdir -p ~/.local/bin mv ./kubectl ~/.local/bin/kubectl # and then append (or prepend) ~/.local/bin to $PATH ```

1. Test to ensure the version you installed is up-to-date:

```bash kubectl version --client ```

Or use this for detailed view of version:

```cmd kubectl version --client --output=yaml ```

### Install using native package management

1. Update the `apt` package index and install packages needed to use the Kubernetes `apt` repository:

```shell 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 gnupg ```

2. 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:

```shell # If the folder `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below. # sudo mkdir -p -m 755 /etc/apt/keyrings curl -fsSL https://pkgs.k8s.io/core:/stable://deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg # allow unprivileged APT programs to read this keyring ```

In releases older than Debian 12 and Ubuntu 22.04, folder `/etc/apt/keyrings` does not exist by default, and it should be created before the curl command.

3. Add the appropriate Kubernetes `apt` repository. If you want to use Kube …(trimmed)

Sources

tasks/tools/install-kubectl-linux.md · docInstall and Set Up kubectl on Linux

Related (11)

part_of {{% heading "prerequisites" %}}describes conf=1
part_of Install kubectl on Linuxdescribes conf=1
part_of Verify kubectl configurationdescribes conf=1
part_of Optional kubectl configurations and pluginsdescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Install kubectl binary with curl on Linuxdescribes conf=1
part_of Install using native package managementdescribes conf=1
part_of Install using other package managementdescribes conf=1
part_of Enable shell autocompletiondescribes conf=1
part_of Configure kubercdescribes conf=1
part_of Install `kubectl convert` plugindescribes conf=1

← all Docs