Guides

How to get started, and accomplish tasks, using Kubernetes.

Edit This Page

Installing kubectl

Overview

kubectl is the command line tool you use to interact with Kubernetes clusters.

You should use a version of kubectl that is at least as new as your server. kubectl version will print the server and client versions. Using the same version of kubectl as your server naturally works; using a newer kubectl than your server also works; but if you use an older kubectl with a newer server you may see odd validation errors .

Download a release

Download kubectl from the official Kubernetes releases:

On MacOS:

wget https://storage.googleapis.com/kubernetes-release/release/v1.4.4/bin/darwin/amd64/kubectl
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

On Linux:

wget https://storage.googleapis.com/kubernetes-release/release/v1.4.4/bin/linux/amd64/kubectl
chmod +x kubectl
mv kubectl /usr/local/bin/kubectl

You may need to sudo the mv; you can put it anywhere in your PATH - some people prefer to install to ~/bin.

Alternatives

Download as part of the Google Cloud SDK

kubectl can be installed as part of the Google Cloud SDK:

First install the Google Cloud SDK.

After Google Cloud SDK installs, run the following command to install kubectl:

gcloud components install kubectl

Do check that the version is sufficiently up-to-date using kubectl version.

Install with brew

If you are on MacOS and using brew, you can install with:

brew install kubectl

The homebrew project is independent from kubernetes, so do check that the version is sufficiently up-to-date using kubectl version.

Enabling shell autocompletion

kubectl includes autocompletion support, which can save a lot of typing!

The completion script itself is generated by kubectl, so you typically just need to invoke it from your profile.

Common examples are provided here, but for more details please consult kubectl completion -h

On Linux, using bash

To add it to your current shell: source <(kubectl completion bash)

To add kubectl autocompletion to your profile (so it is automatically loaded in future shells):

echo "source <(kubectl completion bash)" >> ~/.bashrc

On MacOS, using bash

On MacOS, you will need to install the bash-completion support first:

brew install bash-completion

To add it to your current shell:

source $(brew --prefix)/etc/bash_completion
source <(kubectl completion bash)

To add kubectl autocompletion to your profile (so it is automatically loaded in future shells):

echo "source $(brew --prefix)/etc/bash_completion" >> ~/.bash_profile
echo "source <(kubectl completion bash)" >> ~/.bash_profile

Please note that this only appears to work currently if you install using brew install kubectl, and not if you downloaded kubectl directly.

Analytics Create an Issue Edit this Page