How to setup kubectl on Macos/linux/Windows Operating system
Getting kubectl up and running
The Cluster API server communicates with Kubernetes through kubectl, a command-line application. The kubectl binary is accessible in many operating system package managers, which is typically far more convenient than a manual download and installation process. To install Kubernetes, follow the instructions in the Kubernetes documentation for your specific operating system or package management.
Here is a step-by-step guide to installing the Amazon EKS vended kubectl binaries on macOS, Linux, and Windows. Choose the tab that corresponds to your operating system. These binaries are the same as the upstream community versions and are not specific to Amazon EKS or AWS.
Note
You must use a version of kubectl within one minor version of the Amazon EKS cluster control plane. A 1.21 kubectl client, for example, can connect to clusters running Kubernetes 1.20, 1.21, and 1.22.
Choose the tab that corresponds to the operating system you wish to install kubectl on.
macOS
1- To install kubectl on macOS, follow these steps.
a. From Amazon S3, download the Amazon EKS vended kubectl binary for your cluster’s Kubernetes version.
• Kubernetes 1.22
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.22.6/2022-03-09/ bin/darwin/amd64/kubectl
• Kubernetes 1.21
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.21.2/2021-07-05/ bin/darwin/amd64/kubectl
• Kubernetes 1.20
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.20.4/2021-04-12/ bin/darwin/amd64/kubectl
• Kubernetes 1.19
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.19.6/2021-01-05/ bin/darwin/amd64/kubectl
• Kubernetes 1.18
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.18.9/2020-11-02/ bin/darwin/amd64/kubectl
• Kubernetes 1.17
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.17.12/2020-11-02/ bin/darwin/amd64/kubectl
2. (Optional) Compare the downloaded binary to your binary’s SHA-256 sum.
a. For macOS, get the SHA-256 sum for your cluster’s Kubernetes version.
• Kubernetes 1.22
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/ 1.22.6/2022-03-09/bin/darwin/amd64/kubectl.sha256
• Kubernetes 1.21
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/ 1.21.2/2021-07-05/bin/darwin/amd64/kubectl.sha256
• Kubernetes 1.20
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/ 1.20.4/2021-04-12/bin/darwin/amd64/kubectl.sha256
• Kubernetes 1.19
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/ 1.19.6/2021-01-05/bin/darwin/amd64/kubectl.sha256
b. Check the SHA-256 sum for the binary you just downloaded..
openssl sha1 -sha256 kubectl
c. Compare the SHA-256 sum generated in the command output to the one you downloaded.
This is an SHA-256 file. The two should complement each other.
3. Give the binary execute permissions.
chmod +x ./kubectl
4. Copy the binary to a folder in your PATH environment variable. If you already have kubectl installed, we recommend creating a $HOME/bin/kubectl directory and putting $HOME/bin first in your $PATH.
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
5. Add the $HOME/bin path to your shell initialization file (optional) to specify when you open a shell.
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bash_profile
6. After you’ve installed kubectl, use the following command to check its version:
kubectl version --short --client
Linux
To install kubectl on Linux, follow these instructions.
1. Using the command for your hardware platform, get the Amazon EKS vended kubectl binary for your cluster’s Kubernetes version from Amazon S3.
• Kubernetes 1.22
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.22.6/2022-03-09/bin/linux/amd64/kubectl
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.22.6/2022-03-09/bin/linux/arm64/kubectl
• Kubernetes 1.21
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.21.2/2021-07-05/bin/linux/amd64/kubectl
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.20.4/2021-04-12/bin/linux/amd64/kubectl
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.20.4/2021-04-12/bin/linux/arm64/kubectl
• Kubernetes 1.19
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.19.6/2021-01-05/bin/linux/amd64/kubectl
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.19.6/2021-01-05/bin/linux/arm64/kubectl
2. Optional: Compare the downloaded binary to your binary’s SHA-256 sum.
a. Using the command for your hardware platform, download the SHA-256 sum for your cluster’s Kubernetes version for Linux.
• Kubernetes 1.22
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.22.6/2022-03-09/bin/linux/amd64/kubectl.sha256
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.23.6/2022-03-09/bin/linux/arm64/kubectl.sha256
• Kubernetes 1.21
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.21.2/2021-07-05/bin/linux/amd64/kubectl.sha256
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.21.2/2021-07-05/bin/linux/arm64/kubectl.sha256
• Kubernetes 1.20
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.20.4/2021-04-12/bin/linux/amd64/kubectl.sha256
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.20.4/2021-04-12/bin/linux/arm64/kubectl.sha256
• Kubernetes 1.19
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.19.6/2021-01-05/bin/linux/amd64/kubectl.sha256
curl -o kubectl.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.19.6/2021-01-05/bin/linux/arm64/kubectl.sha256
b. Check the SHA-256 sum of the binary you downloaded.
OpenSSL sha1 -sha256 kubectl
c. Compare the generated SHA-256 sum in the command output to the SHA-256 file you downloaded. The two should complement each other.
Windows
To install kubectl on Windows, follow these instructions.
1. To get started, open a PowerShell terminal.
2. From Amazon S3, download the Amazon EKS vended kubectl binary for your cluster’s Kubernetes version.
• Kubernetes 1.22
curl -o kubectl.exe https://s3.us-west-2.amazonaws.com/amazoneks/1.22.6/2022-03-09/bin/windows/amd64/kubectl.exe
• Kubernetes 1.21
curl -o kubectl.exe https://s3.us-west-2.amazonaws.com/amazoneks/1.21.2/2021-07-05/bin/windows/amd64/kubectl.exe
• Kubernetes 1.20
curl -o kubectl.exe https://s3.us-west-2.amazonaws.com/amazoneks/1.20.4/2021-04-12/bin/windows/amd64/kubectl.exe
• Kubernetes 1.19
curl -o kubectl.exe https://s3.us-west-2.amazonaws.com/amazoneks/1.19.6/2021-01-05/bin/windows/amd64/kubectl.exe
3. (Optional) Compare the downloaded binary to your binary’s SHA-256 sum.
a. For Windows, download the SHA-256 sum for your cluster’s Kubernetes version.
• Kubernetes 1.22
curl -o kubectl.exe.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.22.6/2022-03-09/bin/windows/amd64/kubectl.exe.sha256
• Kubernetes 1.21
curl -o kubectl.exe.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.21.2/2021-07-05/bin/windows/amd64/kubectl.exe.sha256
• Kubernetes 1.20
curl -o kubectl.exe.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.20.4/2021-04-12/bin/windows/amd64/kubectl.exe.sha256
• Kubernetes 1.19
curl -o kubectl.exe.sha256 https://s3.us-west-2.amazonaws.com/amazoneks/1.19.6/2021-01-05/bin/windows/amd64/kubectl.exe.sha256
b. Check the SHA-256 sum of the binary you downloaded.
Get-FileHash kubectl.exe
c. Compare the SHA-256 sum returned by the command output with the SHA-256 file you downloaded. Although the PowerShell output will be in uppercase, the two should be identical.
4. Copy the binary to a folder in your PATH environment variable. Copy the program if you already have a command-line utility directory in your PATH. Otherwise, proceed to the next step.
a. Make a new directory, such as C: bin, for your command-line binaries.
b. In your new directory, copy the kubectl.exe binary.
c. To add the new directory to your PATH environment variable, edit your user or system PATH environment variable.
d. To use the new PATH variable, close your PowerShell terminal and open a new one.
5. After you’ve installed kubectl, use the following command to check its version:
kubectl version --short --client
Leave a Comment