Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install kubectl (the Kubernetes Command Line Tool) on Ubuntu 22.04

Install kubectl with Snap or as a binary, and verify the download.

VPS and Cloud Servers2 min read5 steps7 screenshots

What kubectl is

kubectl is the command line tool for Kubernetes. It talks to a cluster and lets you deploy apps, inspect resources and read logs. To use it you also need a cluster (for example Minikube on your machine, a kubeadm cluster or a cloud one).

Method 1: Snap

Step 1: Install kubectl

sudo snap install kubectl --classic
Installing kubectl with Snap
  • snap is the Snap package manager.
  • install installs a package.
  • kubectl is the package name.
  • --classic lets the package access the whole system, which kubectl needs.

Step 2: Check it

kubectl version --client
The kubectl version
  • version shows the version of kubectl.
  • --client shows the client version only (without connecting to a cluster).

Method 2: The binary

Step 1: Download kubectl

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
Downloading kubectl
  • curl fetches data from a web server.
  • -L follows redirects.
  • -O saves the file under its own name.
  • The part in $(...) asks for the latest stable version number.

Step 2: Download the checksum

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

Step 3: Check the file

echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check
Checking the checksum

You should see kubectl: OK.

Step 4: Install the binary

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Installing the binary
  • -o root -g root sets the owner and group to root.
  • -m 0755 sets the permissions (the owner can write, everyone can read and run).
  • The file goes to /usr/local/bin/kubectl.

Step 5: Check it

kubectl version --client
The kubectl version after the install

Next steps

  • For a local cluster, install Minikube or kind.
  • For a real cluster, install kubeadm and kubelet, or use a managed Kubernetes service.
  • Copy the kubeconfig file of your cluster to ~/.kube/config, then test with kubectl get nodes.

What Kubernetes does

  1. Self-healing. It replaces failed containers.
  2. Resource management. It shares CPU and memory in a smart way.
  3. Rollouts and rollbacks. It updates apps step by step, and can go back.
  4. Horizontal scaling. It adds or removes copies of your app as the load changes.
  5. Service discovery and load balancing.

Quick recap

  • sudo snap install kubectl --classic is the fast way.
  • Or download the binary, check the checksum and install it.
  • Check with kubectl version --client.