⎈ k8s knowledge compiler

Install and Set Up kubectl on macOS [page]deterministic

taskscliapi

##

You must use a kubectl version that is within one minor version difference of your cluster. For example, a v client can communicate with v, v, and v control planes. Using the latest compatible version of kubectl helps avoid unforeseen issues.

## Install kubectl on macOS

The following methods exist for installing kubectl on macOS:

  • [Install kubectl on macOS](#install-kubectl-on-macos) - [Install kubectl binary with curl on macOS](#install-kubectl-binary-with-curl-on-macos) - [Install with Homebrew on macOS](#install-with-homebrew-on-macos) - [Install with Macports on macOS](#install-with-macports-on-macos)
  • [Verify kubectl configuration](#verify-kubectl-configuration)
  • [Optional kubectl configurations and plugins](#optional-kubectl-configurations-and-plugins) - [Enable shell autocompletion](#enable-shell-autocompletion) - [Install `kubectl convert` plugin](#install-kubectl-convert-plugin)

### Install kubectl binary with curl on macOS

1. Download the latest release:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl" curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"

> 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 on Intel macOS, type:

```bash curl -LO "https://dl.k8s.io/release/v/bin/darwin/amd64/kubectl" ```

And for macOS on Apple Silicon, type:

```bash curl -LO "https://dl.k8s.io/release/v/bin/darwin/arm64/kubectl" ```

1. Validate the binary (optional)

Download the kubectl checksum file:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256" curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl.sha256" Validate the kubectl binary against the checksum file:

```bash echo "$(cat kubectl.sha256) kubectl" | shasum -a 256 --check ```

If valid, the output is:

```console kubectl: OK ```

If the check fails, `shasum` exits with nonzero status and prints output similar to:

```console kubectl: FAILED shasum: WARNING: 1 computed checksum did NOT match ```

> Note: Download the same version of the binary and checksum.

1. Make the kubectl binary executable.

```bash chmod +x ./kubectl ```

1. Move the kubectl binary to a file location on your system `PATH`.

```bash sudo mv ./kubectl /usr/local/bin/kubectl sudo chown root: /usr/local/bin/kubectl ```

> Note: Make sure `/usr/local/bin` is in your PATH environment variable.

1. Test to ensure the version you installed is up-to-date:

```bash kubectl version --client ``` Or use this for detailed view of version:

```cmd kubectl version --client --output=yaml ```

1. After installing and validating kubectl, delete the checksum file:

```bash rm kubectl.sha256 ```

### Install with Homebrew on macOS

If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you can install kubectl with Homebrew.

1. Run the installation command:

```bash brew install kubectl ```

or

```bash brew install kubernetes-cli ```

1. Test to ensure the version you installed is up-to-date:

```bash kubectl version --client ```

### Install with Macports on macOS

If you are on macOS and using [Macports](https://macports.org/) package manager, you can install kubectl with Macports.

1. Run the installation command:

```bash sudo port selfupdate sudo port install kubectl ```

1. Test to ensure the version you installed is up-to-date:

```bash kubectl version --client ```

## Verify kubectl configuration

## Optional kubectl …(trimmed)

Sources

tasks/tools/install-kubectl-macos.md · docInstall and Set Up kubectl on macOS

Related (14)

part_of {{% heading "prerequisites" %}}describes conf=1
part_of Install kubectl on macOSdescribes conf=1
part_of Verify kubectl configurationdescribes conf=1
part_of Optional kubectl configurations and pluginsdescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Install kubectl binary with curl on macOSdescribes conf=1
part_of Install with Homebrew on macOSdescribes conf=1
part_of Install with Macports on macOSdescribes conf=1
part_of Enable shell autocompletiondescribes conf=1
part_of Configure kubercdescribes conf=1
part_of Install `kubectl convert` plugindescribes conf=1
part_of Uninstall kubectl on macOSdescribes conf=1
part_of Uninstall kubectl using the command-linedescribes conf=1
part_of Uninstall kubectl using homebrewdescribes conf=1

← all Docs