How to Install kubectl to manage your K8s clusters


kubectl
is a command-line tool used for interacting with Kubernetes clusters. kubectl allows users to manage Kubernetes resources and applications by providing commands to create, inspect, update, and delete various resources within a Kubernetes cluster.

In this post, we'll see how to install kubectl in a Linux OS (it's also valid for macOS) and how to configure it to connect to our K8s clusters

Installation 

  • Download the latest version available
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  • Add execute permissions to the binary:
chmod +x ./kubectl
  • To run it properly, the directory where the kubectl binary is located should be included in the PATH environment variable. For this, we've got two options:

Option 1 - Copy the binary to a directory in your PATH env variable. 

  • Run the following command to know what directories are defined in your PATH
echo $PATH
  • For example, we could move it to /usr/local/bin with the command
sudo mv kubectl /usr/local/bin/kubectl

Option 2 - Append the directory where you want to have kubectl to the PATH 

  • Run the following the command
export PATH=$PATH:[/YOUR/KUBECTL/PATH]

  • Lastly, verify kubectl is installed and accessible
  • kubectl version --short --client

Connect to your K8s cluster

Now the question is - how do we connect kubectl to our K8s cluster? if I've got more than one cluster, how does kubectl know which cluster to connect to? and how do we authenticate to access that K8s cluster?

The answer to all these questions is the kubeconfig file. The kubeconfig is a file, with a predefined structure, that specifies the K8s you can access to and how. kubectl uses the info of this file to connect to your K8s clusters.
In the next post, we'll dive into what the kubeconfig is and how to manage it. Click in the link below to understand better how we connect kubectl to our K8s clusters:


Previous Post Next Post