Installing and setting Up kubectl on Linux or Ubuntu

Suresh yadav
Cypik
Published in
4 min readMay 28, 2024
Cypik.com

What is Kubernetes?

Kubernetes is an open-source project that has become one of the most popular container orchestration tools around; it allows you to deploy and manage multi-container applications at scale.

Kubernetes advantages

1. Kubernetes simplifies management of storage, secrets, and other application-related resources

2. Kubernetes manages app health, replication, load balancing, and hardware resource allocation for you

3. Kubernetes applications can run in hybrid cloud and multi-cloud environments

What is kubectl?

kubectlis the Kubernetes-specific command-line tool that lets you communicate and control Kubernetes clusters. Whether you’re creating, managing, or deleting resources on your Kubernetes platform, Kubectl is an essential tool.

Why do you need kubectl?

kubectlis the most common way to make HTTP requests to the Kubernetes API, and it’s used to run Kubernetes operations, deploy containerized applications, inspect and manage the resources in your cluster, as well as perform monitoring tasks and view the logs of the system.

Installing kubectl on Linux :

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/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 v1.30.1 on Linux, type:

curl -LO https://dl.k8s.io/release/v1.30.1/bin/linux/amd64/kubectl

Step 2. 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"

Validate the kubectl binary against the checksum file:

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

Step 3. 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

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

kubectl version --client

Or use this for a detailed view of the version:

kubectl version --client --output=yaml

Install using native package management

Installing Kubectl on Ubuntu:

  1. Update theapt package index and install the packages needed to use the Kubernetes aptrepository:
sudo apt-get update 
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg

2. Download the Google Cloud public signing key:

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg

3. Add the appropriate Kubernetes apt repository. If you want to use a Kubernetes version different than v1.30, replace v1.30 with the desired minor version in the command below:

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list

4. Updateapt the 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. You can create this directory if you need to, making it world-readable but writeable only by admins.

Verify kubectl configuration

In order for kubectl to find and access a Kubernetes cluster, it needs a kubeconfig file, which is created automatically when you create a cluster using kube-up.sh or successfully deploy a Minikube cluster. By default, kubectl configuration is located at ~/.kube/config.

Check that kubectl is properly configured by getting the cluster state:

kubectl cluster-info

Simplifying Kubernetes Service Install Minikube Management: A Step-by-Step Guide

Enjoy it! 🍻 That’s It; we are done...

For seamless Cloud Management incorporating DevOps as the core of the methodology, reach out to us at info@cypik.com

Cypik

About the author:

My name is Suresh Yadav, and I am an experienced Linux enthusiast and DevOps engineer. I’m passionate about automating and streamlining development processes, and currently, I work as a DevOps Engineer at Cypik. I specialize in cloud technologies, with a focus on Google Cloud Platform (GCP), AWS cloud services, and Terraform’s ability to streamline operations and increase efficiency.

--

--

Suresh yadav
Cypik
Writer for

DevOps Engineer || DevOps || GCP || Aws || Jenkins || Networking || Terraform || Github || Mysql || Ansible || Linux || Docker