4.7 KiB
reviewers | title | content_type | weight | card | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Install and Set Up kubectl on macOS | task | 10 |
|
{{% heading "prerequisites" %}}
You must use a kubectl version that is within one minor version difference of your cluster. For example, a v{{< skew latestVersion >}} client can communicate with v{{< skew prevMinorVersion >}}, v{{< skew latestVersion >}}, and v{{< skew nextMinorVersion >}} control planes. Using the latest version of kubectl helps avoid unforeseen issues.
Install kubectl on macOS
The following methods exist for installing kubectl on macOS:
- Install kubectl binary with curl on macOS
- Install with Homebrew on macOS
- Install with Macports on macOS
- Install on macOS as part of the Google Cloud SDK
Install kubectl binary with curl on macOS
-
Download the latest release:
{{< tabs name="download_binary_macos" >}} {{< tab name="Intel" codelang="bash" >}} curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl" {{< /tab >}} {{< tab name="Apple Silicon" codelang="bash" >}} curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl" {{< /tab >}} {{< /tabs >}}
{{< note >}} To download a specific version, replace the
$(curl -L -s https://dl.k8s.io/release/stable.txt)
portion of the command with the specific version.For example, to download version {{< param "fullversion" >}} on Intel macOS, type:
curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl"
And for macOS on Apple Silicon, type:
curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/darwin/arm64/kubectl"
{{< /note >}}
-
Validate the binary (optional)
Download the kubectl checksum file:
{{< tabs name="download_checksum_macos" >}} {{< tab name="Intel" codelang="bash" >}} curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256" {{< /tab >}} {{< tab name="Apple Silicon" codelang="bash" >}} curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl.sha256" {{< /tab >}} {{< /tabs >}}
Validate the kubectl binary against the checksum file:
echo "$(<kubectl.sha256) kubectl" | shasum -a 256 --check
If valid, the output is:
kubectl: OK
If the check fails,
shasum
exits with nonzero status and prints output similar to:kubectl: FAILED shasum: WARNING: 1 computed checksum did NOT match
{{< note >}} Download the same version of the binary and checksum. {{< /note >}}
-
Make the kubectl binary executable.
chmod +x ./kubectl
-
Move the kubectl binary to a file location on your system
PATH
.sudo mv ./kubectl /usr/local/bin/kubectl sudo chown root: /usr/local/bin/kubectl
-
Test to ensure the version you installed is up-to-date:
kubectl version --client
Install with Homebrew on macOS
If you are on macOS and using Homebrew package manager, you can install kubectl with Homebrew.
-
Run the installation command:
brew install kubectl
or
brew install kubernetes-cli
-
Test to ensure the version you installed is up-to-date:
kubectl version --client
Install with Macports on macOS
If you are on macOS and using Macports package manager, you can install kubectl with Macports.
-
Run the installation command:
sudo port selfupdate sudo port install kubectl
-
Test to ensure the version you installed is up-to-date:
kubectl version --client
Install on macOS as part of the Google Cloud SDK
{{< include "included/install-kubectl-gcloud.md" >}}
Verify kubectl configuration
{{< include "included/verify-kubectl.md" >}}
Optional kubectl configurations
Enable shell autocompletion
kubectl provides autocompletion support for Bash and Zsh, which can save you a lot of typing.
Below are the procedures to set up autocompletion for Bash and Zsh.
{{< tabs name="kubectl_autocompletion" >}} {{< tab name="Bash" include="included/optional-kubectl-configs-bash-mac.md" />}} {{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}} {{< /tabs >}}
{{% heading "whatsnext" %}}
{{< include "included/kubectl-whats-next.md" >}}