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 https://packages.cloud.google.com/apt/doc/apt-key.gpg \ && echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list \ && sudo apt update \ && sudo apt-get install -y kubectl
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
First published: 23rd June 2021