Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Set Up Kubectl On Your Local Machine



Run the following command chain in order to install kubectl through package management, in order to ensure you get the latest updates.

sudo apt-get update \
  && sudo apt-get install -y apt-transport-https ca-certificates curl \
  && sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg \
  && echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list \
  && sudo apt update \
  && sudo apt-get install -y kubectl

This installs version 1.21.2 at the time of writing this post.


Alternatively, you can install through snaps with:

snap install kubectl --classic


Once you have kubectl installed, you won't be able to use it until you configure your Kubernetes profile to point to your cluster.

SSH into one of your master/controller servers and open the configuration file in order to copy it to your clipboard:

sudo editor /etc/rancher/k3s/k3s.yaml

Now create a profile space on your local machine for Kubernetes, and paste the config you just copied, into it:

mkdir $HOME/.kube
sudo editor $HOME/.kube/config

Now find the line that states:


... and change it to the IP address of your load balancer. E.g.


Now you can run your kubectl commands like:

kubectl get node


Last updated: 23rd June 2021
First published: 23rd June 2021