Update install-kubectl.md to use tabs for the different Operating Systems (#26682)

* top-level tags and change to included files

* revert content to main windows page

* include gcloud and update toc

* add leading blank line

* add text to avoid YAML error from Netlify

* remove YAML delimiter error

* removed redundant weight key

* add front matter and toc shortcode

* test to see if toc is fixed in included page

* update macos toc to show difference

* use static toc instead of shortcode

* uniqueness for gcloud install headers

* Move to model suggested in https://github.com/kubernetes/website/pull/26682#discussion_r585091797

* correct link to included/install-kubectl-gcloud.md

* correction of links to per-OS pages

* try a different way to use path to per-OS links

* correction of brainfart

* remove .md from link destination for per-OS pages

* modify how auto-competion steps are displayed

* remove redundant file

* correction of include - change % to <

* remove closing tag as not needed

* try and hide this directory from the ToC on the left

* remove erroneous "include="

* addressing feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586325123

* addressing feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586326346

* addressing feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586326604

* addressing feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586327212

* https://github.com/kubernetes/website/pull/26682#discussion_r586327856

* consistent verb usage as per feedback: https://github.com/kubernetes/website/pull/26682#discussion_r586328497

* update redirects as existing page is being deleted
This commit is contained in:
Tom Kivlin
2021-03-05 03:04:21 +00:00
committed by GitHub
parent b43aafe2ae
commit 87e3291aaa
13 changed files with 770 additions and 646 deletions
@@ -0,0 +1,172 @@
---
reviewers:
- mikedanese
title: Install and Set Up kubectl on Linux
content_type: task
weight: 10
card:
name: tasks
weight: 20
title: Install kubectl on Linux
---
## {{% heading "prerequisites" %}}
You must use a kubectl version that is within one minor version difference of your cluster.
For example, a v1.2 client should work with v1.1, v1.2, and v1.3 master.
Using the latest version of kubectl helps avoid unforeseen issues.
## Install kubectl on Linux
The following methods exist for installing kubectl on Linux:
- [Install kubectl binary with curl on Linux](#install-kubectl-binary-with-curl-on-linux)
- [Install using native package management](#install-using-native-package-management)
- [Install using other package management](#install-using-other-package-management)
- [Install on Linux as part of the Google Cloud SDK](#install-on-linux-as-part-of-the-google-cloud-sdk)
### Install kubectl binary with curl on Linux
1. Download the latest release with the command:
```bash
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/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 {{< param "fullversion" >}} on Linux, type:
```bash
curl -LO https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/linux/amd64/kubectl
```
{{< /note >}}
1. Validate the binary (optional)
Download the kubectl checksum file:
```bash
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
```
Validate the kubectl binary against the checksum file:
```bash
echo "$(<kubectl.sha256) kubectl" | sha256sum --check
```
If valid, the output is:
```console
kubectl: OK
```
If the check fails, `sha256` exits with nonzero status and prints output similar to:
```bash
kubectl: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
```
{{< note >}}
Download the same version of the binary and checksum.
{{< /note >}}
1. Install kubectl
```bash
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
```
{{< note >}}
If you do not have root access on the target system, you can still install kubectl to the `~/.local/bin` directory:
```bash
mkdir -p ~/.local/bin/kubectl
mv ./kubectl ~/.local/bin/kubectl
# and then add ~/.local/bin/kubectl to $PATH
```
{{< /note >}}
1. Test to ensure the version you installed is up-to-date:
```bash
kubectl version --client
```
### Install using native package management
{{< tabs name="kubectl_install" >}}
{{< tab name="Ubuntu, Debian or HypriotOS" codelang="bash" >}}
sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2 curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
{{< /tab >}}
{{< tab name="CentOS, RHEL or Fedora" codelang="bash" >}}cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubectl
{{< /tab >}}
{{< /tabs >}}
### Install using other package management
{{< tabs name="other_kubectl_install" >}}
{{% tab name="Snap" %}}
If you are on Ubuntu or another Linux distribution that support [snap](https://snapcraft.io/docs/core/install) package manager, kubectl is available as a [snap](https://snapcraft.io/) application.
```shell
snap install kubectl --classic
kubectl version --client
```
{{% /tab %}}
{{% tab name="Homebrew" %}}
If you are on Linux and using [Homebrew](https://docs.brew.sh/Homebrew-on-Linux) package manager, kubectl is available for [installation](https://docs.brew.sh/Homebrew-on-Linux#install).
```shell
brew install kubectl
kubectl version --client
```
{{% /tab %}}
{{< /tabs >}}
### Install on Linux 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-linux.md" />}}
{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}}
{{< /tabs >}}
## {{% heading "whatsnext" %}}
{{< include "included/kubectl-whats-next.md" >}}