Install kubectl on Ubuntu Instance | How to install kubectl in Ubuntu

Kubernetes uses a command line utility called kubectl for communicating with the cluster API server. It is a tool for controlling Kubernetes clusters. kubectl looks for a file named config in the $HOME directory.

How to install Kubectl in Ubuntu instance

  1. Update the apt package index and install packages needed to use the Kubernetes apt repository:

     sudo apt-get update
     sudo apt-get install -y ca-certificates curl
    

    If you use Debian 9 (stretch) or earlier you would also need to install apt-transport-https:

     sudo apt-get install -y apt-transport-https
    
  2. Download the Google Cloud public signing key:

     curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-archive-keyring.gpg
    
  3. Add the Kubernetes apt repository:

     echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    
  4. Update apt package index with the new repository and install kubectl:

     sudo apt-get update
     sudo apt-get install -y kubectl
    
  5. Verify if kubectl got installed

     kubectl version --short --client