Estimated reading time: 2 minutes
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 using the apt package manager.
Table of contents
Before you install
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.29, then you can install either of 1.28, 1.29 or 1.30 versions of kubectl
.
Installing the latest stable version of kubectl
on Ubuntu and other Debian-based systems
Now let’s look at the commands to install the latest stable kubectl version on Ubuntu and other Debian-based systems.
Step 1: 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
Test your installation of kubectl
on Ubuntu
Test your installation by running the version
command on Ubuntu. 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
Before you go
If you want to install the Kubectl tool using the binaries instead of the package manager, check out our quick guide for installing Kubectl to interact with k8s.