How to install Kubectl on Mac
This blog shows you how to install Kubectl, a command line interface for running commands against Kubernetes clusters. kubectl looks for a file named config in the $HOME/.kube
directory.
Installing kubectl on Mac
There are 3 different ways to install kubectl
on Mac. You can choose anyone!
Install kubectl binary with curl on macOS
Following are the steps to install kubectl binary with curl on macOS:
Step #1 Download the latest release:
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
Step #2 To download a specific version, replace the $(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)
with the specific version.
For example, to download version v1.15.0 on macOS, type:
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/darwin/amd64/kubectl
Step #3 Make the kubectl binary executable.
chmod +x ./kubectl
Step #4 Move the binary in to your PATH.
sudo mv ./kubectl /usr/local/bin/kubectl
Step #5 Test to ensure the version you installed is up-to-date:
kubectl version
Install with Homebrew on macOS
If you are using Homebrew package manager, you can install kubectl with following Homebrew command.
Step #1 Run the installation command:
brew install kubernetes-cli
Step #2 Test to ensure the version you installed is up-to-date:
kubectl version
Install with Macports on macOS
If you are using Macports package manager, you can install kubectl with following Macports command.
Step #1 Run the installation command:
sudo port selfupdate
sudo port install kubectl
Step #2 Test to ensure the version you installed is up-to-date:
kubectl version
Set kubectl alias
To avoid typing kubectl
everytime, you can set below alias
in ~/.bash_profile
file.
alias k='kubectl'
After editing ~/.bash_profile
file, you must load the profile using below command.
source ~/.bash_profile
Happy coding…