Installing Kubectl

In Progress
Lesson Progress
0% Complete

Kubectl is a command line interface for running commands against Kubernetes clusters. kubectl is generally installed before installing Minikube, but we can also install it after.

Once installed, kubectl receives its configuration automatically for Minikube Kubernetes cluster access.

However, in other Kubernetes cluster setups, we may need to configure the cluster access points and certificates required by kubectl to access the cluster.

There are different methods that can be used to install kubectl, which are mentioned in the Kubernetes documentation.

For best results, it is recommended to keep kubectl at the same version with the Kubernetes run by Minikube – at the time the course was written the latest stable release was v1.14.1.

Next, we will look at a few steps to install it on Linux, macOS, and Windows systems.

Install Kubectl on Linux

To install kubectl on Linux, follow the instruction below:

Download the latest stable kubectl binary, make it executable and move it to the PATH:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

To download and setup a specific version of kubectl (such as v1.14.1), issue the following command:

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.1/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

Install Kubectl on Mac OS

There are two ways to install kubectl on macOS: manually and using the Homebrew package manager. Next, we will provide instructions for both methods.

To manually install kubectl, download the latest stable kubectl binary, make it executable and move it to the PATH with the following command:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

To download and setup a specific version of kubectl (such as v1.14.1), issue the following command:

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.1/bin/darwin/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/

To install kubectl with Homebrew package manager, issue the following command:

 brew install kubernetes-cli

Install kubectl on Windows

To install kubectl, we can download the binary directly or use curl from the CLI. Once downloaded the binary needs to be added to the PATH.

Direct download link for v1.14.1 binary (just click below):

https://storage.googleapis.com/kubernetes-release/release/v1.14.1/bin/windows/amd64/kubectl.exe

Obtain the latest kubectl stable release version number from the link below, and if needed edit the download link for the binary from above: 

https://storage.googleapis.com/kubernetes-release/release/stable.txt

Use the curl command (if installed) from the CLI:

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.1/bin/windows/amd64/kubectl.exe

Once downloaded, move the kubectl binary to the PATH.

kubectl Configuration File

To access the Kubernetes cluster, the kubectl client needs the master node endpoint and appropriate credentials to be able to interact with the API server running on the master node.

While starting Minikube, the startup process creates, by default, a configuration file, config, inside the .kube directory (often referred to as the dot-kube-config file), which resides in the user’s home directory.

The configuration file has all the connection details required by kubectl. By default, the kubectl binary parses this file to find the master node’s connection endpoint, along with credentials.

To look at the connection details, we can either see the content of the ~/.kube/config file (on Linux) or run the following command:

kubectl config view