Created
August 27, 2020 05:32
-
-
Save oke-py/bb855a5a40ec97a31a1f07615e22e48d to your computer and use it in GitHub Desktop.
git diff upstream/release-1.17 fb6364d <file>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/content/en/docs/tasks/tools/install-kubectl.md b/content/en/docs/tasks/tools/install-kubectl.md | |
index 83c9d1761..2d9c8f1ad 100644 | |
--- a/content/en/docs/tasks/tools/install-kubectl.md | |
+++ b/content/en/docs/tasks/tools/install-kubectl.md | |
@@ -2,7 +2,7 @@ | |
reviewers: | |
- mikedanese | |
title: Install and Set Up kubectl | |
-content_template: templates/task | |
+content_type: task | |
weight: 10 | |
card: | |
name: tasks | |
@@ -10,15 +10,21 @@ card: | |
title: Install kubectl | |
--- | |
-{{% capture overview %}} | |
-The Kubernetes command-line tool, [kubectl](/docs/user-guide/kubectl/), allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. For a complete list of kubectl operations, see [Overview of kubectl](/docs/reference/kubectl/overview/). | |
-{{% /capture %}} | |
+<!-- overview --> | |
+The Kubernetes command-line tool, [kubectl](/docs/reference/kubectl/kubectl/), allows | |
+you to run commands against Kubernetes clusters. | |
+You can use kubectl to deploy applications, inspect and manage cluster resources, | |
+and view logs. For a complete list of kubectl operations, see | |
+[Overview of kubectl](/docs/reference/kubectl/overview/). | |
-{{% capture 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. | |
-{{% /capture %}} | |
-{{% capture steps %}} | |
+## {{% 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. | |
+ | |
+<!-- steps --> | |
## Install kubectl on Linux | |
@@ -27,7 +33,7 @@ You must use a kubectl version that is within one minor version difference of yo | |
1. Download the latest release with the command: | |
``` | |
- curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl | |
+ curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl" | |
``` | |
To download a specific version, replace the `$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)` portion of the command with the specific version. | |
@@ -59,12 +65,13 @@ You must use a kubectl version that is within one minor version difference of yo | |
{{< tabs name="kubectl_install" >}} | |
{{< tab name="Ubuntu, Debian or HypriotOS" codelang="bash" >}} | |
-sudo apt-get update && sudo apt-get install -y apt-transport-https | |
+sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2 | |
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 | |
@@ -87,53 +94,60 @@ If you are on Ubuntu or another Linux distribution that support [snap](https://s | |
```shell | |
snap install kubectl --classic | |
-kubectl version | |
+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 | |
+kubectl version --client | |
``` | |
+ | |
{{% /tab %}} | |
+ | |
{{< /tabs >}} | |
+ | |
## Install kubectl on macOS | |
### Install kubectl binary with curl on macOS | |
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" | |
- ``` | |
+ ```bash | |
+ curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl" | |
+ ``` | |
- To download a specific version, replace the `$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)` portion of the command with the specific version. | |
+ To download a specific version, replace the `$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)` portion of the command with the specific version. | |
- For example, to download version {{< param "fullversion" >}} on macOS, type: | |
- | |
- ``` | |
- curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl | |
- ``` | |
+ For example, to download version {{< param "fullversion" >}} on macOS, type: | |
-2. Make the kubectl binary executable. | |
+ ```bash | |
+ curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl | |
+ ``` | |
- ``` | |
- chmod +x ./kubectl | |
- ``` | |
+ Make the kubectl binary executable. | |
+ | |
+ ```bash | |
+ chmod +x ./kubectl | |
+ ``` | |
3. Move the binary in to your PATH. | |
- ``` | |
- sudo mv ./kubectl /usr/local/bin/kubectl | |
- ``` | |
+ ```bash | |
+ sudo mv ./kubectl /usr/local/bin/kubectl | |
+ ``` | |
+ | |
4. Test to ensure the version you installed is up-to-date: | |
- ``` | |
- kubectl version --client | |
- ``` | |
+ ```bash | |
+ kubectl version --client | |
+ ``` | |
### Install with Homebrew on macOS | |
@@ -141,20 +155,21 @@ If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you | |
1. Run the installation command: | |
- ``` | |
- brew install kubectl | |
- ``` | |
- or | |
- | |
- ``` | |
- brew install kubernetes-cli | |
- ``` | |
+ ```bash | |
+ brew install kubectl | |
+ ``` | |
+ | |
+ or | |
+ | |
+ ```bash | |
+ brew install kubernetes-cli | |
+ ``` | |
2. Test to ensure the version you installed is up-to-date: | |
- ``` | |
- kubectl version --client | |
- ``` | |
+ ```bash | |
+ kubectl version --client | |
+ ``` | |
### Install with Macports on macOS | |
@@ -162,16 +177,16 @@ If you are on macOS and using [Macports](https://macports.org/) package manager, | |
1. Run the installation command: | |
- ``` | |
- sudo port selfupdate | |
- sudo port install kubectl | |
- ``` | |
- | |
+ ```bash | |
+ sudo port selfupdate | |
+ sudo port install kubectl | |
+ ``` | |
+ | |
2. Test to ensure the version you installed is up-to-date: | |
- ``` | |
- kubectl version --client | |
- ``` | |
+ ```bash | |
+ kubectl version --client | |
+ ``` | |
## Install kubectl on Windows | |
@@ -179,20 +194,22 @@ If you are on macOS and using [Macports](https://macports.org/) package manager, | |
1. Download the latest release {{< param "fullversion" >}} from [this link](https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe). | |
- Or if you have `curl` installed, use this command: | |
+ Or if you have `curl` installed, use this command: | |
- ``` | |
- curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe | |
- ``` | |
+ ```bash | |
+ curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe | |
+ ``` | |
- To find out the latest stable version (for example, for scripting), take a look at [https://storage.googleapis.com/kubernetes-release/release/stable.txt](https://storage.googleapis.com/kubernetes-release/release/stable.txt). | |
+ To find out the latest stable version (for example, for scripting), take a look at [https://storage.googleapis.com/kubernetes-release/release/stable.txt](https://storage.googleapis.com/kubernetes-release/release/stable.txt). | |
2. Add the binary in to your PATH. | |
+ | |
3. Test to ensure the version of `kubectl` is the same as downloaded: | |
- ``` | |
- kubectl version --client | |
- ``` | |
+ ```bash | |
+ kubectl version --client | |
+ ``` | |
+ | |
{{< note >}} | |
[Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/#kubernetes) adds its own version of `kubectl` to PATH. | |
If you have installed Docker Desktop before, you may need to place your PATH entry before the one added by the Docker Desktop installer or remove the Docker Desktop's `kubectl`. | |
@@ -204,100 +221,118 @@ If you are on Windows and using [Powershell Gallery](https://www.powershellgalle | |
1. Run the installation commands (making sure to specify a `DownloadLocation`): | |
+ ```powershell | |
+ Install-Script -Name 'install-kubectl' -Scope CurrentUser -Force | |
+ install-kubectl.ps1 [-DownloadLocation <path>] | |
``` | |
- Install-Script -Name install-kubectl -Scope CurrentUser -Force | |
- install-kubectl.ps1 [-DownloadLocation <path>] | |
- ``` | |
- | |
- {{< note >}}If you do not specify a `DownloadLocation`, `kubectl` will be installed in the user's temp Directory.{{< /note >}} | |
- | |
- The installer creates `$HOME/.kube` and instructs it to create a config file | |
+ | |
+ {{< note >}} | |
+ If you do not specify a `DownloadLocation`, `kubectl` will be installed in the user's temp Directory. | |
+ {{< /note >}} | |
+ | |
+ The installer creates `$HOME/.kube` and instructs it to create a config file. | |
2. Test to ensure the version you installed is up-to-date: | |
- ``` | |
- kubectl version --client | |
- ``` | |
+ ```powershell | |
+ kubectl version --client | |
+ ``` | |
- {{< note >}}Updating the installation is performed by rerunning the two commands listed in step 1.{{< /note >}} | |
+{{< note >}} | |
+Updating the installation is performed by rerunning the two commands listed in step 1. | |
+{{< /note >}} | |
### Install on Windows using Chocolatey or Scoop | |
-To install kubectl on Windows you can use either [Chocolatey](https://chocolatey.org) package manager or [Scoop](https://scoop.sh) command-line installer. | |
-{{< tabs name="kubectl_win_install" >}} | |
-{{% tab name="choco" %}} | |
+1. To install kubectl on Windows you can use either [Chocolatey](https://chocolatey.org) package manager or [Scoop](https://scoop.sh) command-line installer. | |
- choco install kubernetes-cli | |
- | |
-{{% /tab %}} | |
-{{% tab name="scoop" %}} | |
+ {{< tabs name="kubectl_win_install" >}} | |
+ {{% tab name="choco" %}} | |
+ ```powershell | |
+ choco install kubernetes-cli | |
+ ``` | |
+ {{% /tab %}} | |
+ {{% tab name="scoop" %}} | |
+ ```powershell | |
+ scoop install kubectl | |
+ ``` | |
+ {{% /tab %}} | |
+ {{< /tabs >}} | |
- scoop install kubectl | |
-{{% /tab %}} | |
-{{< /tabs >}} | |
2. Test to ensure the version you installed is up-to-date: | |
- ``` | |
- kubectl version --client | |
- ``` | |
+ ```powershell | |
+ kubectl version --client | |
+ ``` | |
3. Navigate to your home directory: | |
- ``` | |
- cd %USERPROFILE% | |
- ``` | |
+ ```powershell | |
+ # If you're using cmd.exe, run: cd %USERPROFILE% | |
+ cd ~ | |
+ ``` | |
+ | |
4. Create the `.kube` directory: | |
- ``` | |
- mkdir .kube | |
- ``` | |
+ ```powershell | |
+ mkdir .kube | |
+ ``` | |
5. Change to the `.kube` directory you just created: | |
- ``` | |
- cd .kube | |
- ``` | |
+ ```powershell | |
+ cd .kube | |
+ ``` | |
6. Configure kubectl to use a remote Kubernetes cluster: | |
- ``` | |
- New-Item config -type file | |
- ``` | |
- | |
- {{< note >}}Edit the config file with a text editor of your choice, such as Notepad.{{< /note >}} | |
+ ```powershell | |
+ New-Item config -type file | |
+ ``` | |
+ | |
+{{< note >}} | |
+Edit the config file with a text editor of your choice, such as Notepad. | |
+{{< /note >}} | |
## Download as part of the Google Cloud SDK | |
You can install kubectl as part of the Google Cloud SDK. | |
1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/). | |
+ | |
2. Run the `kubectl` installation command: | |
- ``` | |
- gcloud components install kubectl | |
- ``` | |
- | |
+ ```shell | |
+ gcloud components install kubectl | |
+ ``` | |
+ | |
3. Test to ensure the version you installed is up-to-date: | |
- ``` | |
- kubectl version --client | |
- ``` | |
+ ```shell | |
+ kubectl version --client | |
+ ``` | |
-## Verifying kubectl configuration | |
+## Verifying kubectl configuration | |
-In order for kubectl to find and access a Kubernetes cluster, it needs a [kubeconfig file](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/), which is created automatically when you create a cluster using [kube-up.sh](https://github.com/kubernetes/kubernetes/blob/master/cluster/kube-up.sh) or successfully deploy a Minikube cluster. By default, kubectl configuration is located at `~/.kube/config`. | |
+In order for kubectl to find and access a Kubernetes cluster, it needs a | |
+[kubeconfig file](/docs/concepts/configuration/organize-cluster-access-kubeconfig/), | |
+which is created automatically when you create a cluster using | |
+[kube-up.sh](https://github.com/kubernetes/kubernetes/blob/master/cluster/kube-up.sh) | |
+or successfully deploy a Minikube cluster. | |
+By default, kubectl configuration is located at `~/.kube/config`. | |
Check that kubectl is properly configured by getting the cluster state: | |
```shell | |
kubectl cluster-info | |
``` | |
+ | |
If you see a URL response, kubectl is correctly configured to access your cluster. | |
If you see a message similar to the following, kubectl is not configured correctly or is not able to connect to a Kubernetes cluster. | |
-```shell | |
+``` | |
The connection to the server <server-name:port> was refused - did you specify the right host or port? | |
``` | |
@@ -335,7 +370,7 @@ The above commands create `/usr/share/bash-completion/bash_completion`, which is | |
To find out, reload your shell and run `type _init_completion`. If the command succeeds, you're already set, otherwise add the following to your `~/.bashrc` file: | |
-```shell | |
+```bash | |
source /usr/share/bash-completion/bash_completion | |
``` | |
@@ -347,21 +382,20 @@ You now need to ensure that the kubectl completion script gets sourced in all yo | |
- Source the completion script in your `~/.bashrc` file: | |
- ```shell | |
- echo 'source <(kubectl completion bash)' >>~/.bashrc | |
- ``` | |
- | |
+ ```bash | |
+ echo 'source <(kubectl completion bash)' >>~/.bashrc | |
+ ``` | |
- Add the completion script to the `/etc/bash_completion.d` directory: | |
- ```shell | |
- kubectl completion bash >/etc/bash_completion.d/kubectl | |
- ``` | |
-- If you have an alias for kubectl, you can extend shell completion to work with that alias: | |
+ ```bash | |
+ kubectl completion bash >/etc/bash_completion.d/kubectl | |
+ ``` | |
+If you have an alias for kubectl, you can extend shell completion to work with that alias: | |
- ```shell | |
- echo 'alias k=kubectl' >>~/.bashrc | |
- echo 'complete -F __start_kubectl k' >>~/.bashrc | |
- ``` | |
+```bash | |
+echo 'alias k=kubectl' >>~/.bashrc | |
+echo 'complete -F __start_kubectl k' >>~/.bashrc | |
+``` | |
{{< note >}} | |
bash-completion sources all completion scripts in `/etc/bash_completion.d`. | |
@@ -382,26 +416,26 @@ The kubectl completion script for Bash can be generated with `kubectl completion | |
However, the kubectl completion script depends on [**bash-completion**](https://github.com/scop/bash-completion) which you thus have to previously install. | |
{{< warning>}} | |
-there are two versions of bash-completion, v1 and v2. V1 is for Bash 3.2 (which is the default on macOS), and v2 is for Bash 4.1+. The kubectl completion script **doesn't work** correctly with bash-completion v1 and Bash 3.2. It requires **bash-completion v2** and **Bash 4.1+**. Thus, to be able to correctly use kubectl completion on macOS, you have to install and use Bash 4.1+ ([*instructions*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)). The following instructions assume that you use Bash 4.1+ (that is, any Bash version of 4.1 or newer). | |
+There are two versions of bash-completion, v1 and v2. V1 is for Bash 3.2 (which is the default on macOS), and v2 is for Bash 4.1+. The kubectl completion script **doesn't work** correctly with bash-completion v1 and Bash 3.2. It requires **bash-completion v2** and **Bash 4.1+**. Thus, to be able to correctly use kubectl completion on macOS, you have to install and use Bash 4.1+ ([*instructions*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)). The following instructions assume that you use Bash 4.1+ (that is, any Bash version of 4.1 or newer). | |
{{< /warning >}} | |
### Upgrade Bash | |
The instructions here assume you use Bash 4.1+. You can check your Bash's version by running: | |
-```shell | |
+```bash | |
echo $BASH_VERSION | |
``` | |
If it is too old, you can install/upgrade it using Homebrew: | |
-```shell | |
+```bash | |
brew install bash | |
``` | |
Reload your shell and verify that the desired version is being used: | |
-```shell | |
+```bash | |
echo $BASH_VERSION $SHELL | |
``` | |
@@ -415,13 +449,13 @@ As mentioned, these instructions assume you use Bash 4.1+, which means you will | |
You can test if you have bash-completion v2 already installed with `type _init_completion`. If not, you can install it with Homebrew: | |
-```shell | |
+```bash | |
brew install bash-completion@2 | |
``` | |
-As stated in the output of this command, add the following to your `~/.bashrc` file: | |
+As stated in the output of this command, add the following to your `~/.bash_profile` file: | |
-```shell | |
+```bash | |
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d" | |
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" | |
``` | |
@@ -432,31 +466,31 @@ Reload your shell and verify that bash-completion v2 is correctly installed with | |
You now have to ensure that the kubectl completion script gets sourced in all your shell sessions. There are multiple ways to achieve this: | |
-- Source the completion script in your `~/.bashrc` file: | |
+- Source the completion script in your `~/.bash_profile` file: | |
- ```shell | |
- echo 'source <(kubectl completion bash)' >>~/.bashrc | |
+ ```bash | |
+ echo 'source <(kubectl completion bash)' >>~/.bash_profile | |
``` | |
- Add the completion script to the `/usr/local/etc/bash_completion.d` directory: | |
- ```shell | |
+ ```bash | |
kubectl completion bash >/usr/local/etc/bash_completion.d/kubectl | |
``` | |
- If you have an alias for kubectl, you can extend shell completion to work with that alias: | |
- ```shell | |
- echo 'alias k=kubectl' >>~/.bashrc | |
- echo 'complete -F __start_kubectl k' >>~/.bashrc | |
+ ```bash | |
+ echo 'alias k=kubectl' >>~/.bash_profile | |
+ echo 'complete -F __start_kubectl k' >>~/.bash_profile | |
``` | |
- | |
+ | |
- If you installed kubectl with Homebrew (as explained [above](#install-with-homebrew-on-macos)), then the kubectl completion script should already be in `/usr/local/etc/bash_completion.d/kubectl`. In that case, you don't need to do anything. | |
-{{< note >}} | |
-the Homebrew installation of bash-completion v2 sources all the files in the `BASH_COMPLETION_COMPAT_DIR` directory, that's why the latter two methods work. | |
-{{< /note >}} | |
+ {{< note >}} | |
+ The Homebrew installation of bash-completion v2 sources all the files in the `BASH_COMPLETION_COMPAT_DIR` directory, that's why the latter two methods work. | |
+ {{< /note >}} | |
In any case, after reloading your shell, kubectl completion should be working. | |
{{% /tab %}} | |
@@ -467,34 +501,34 @@ The kubectl completion script for Zsh can be generated with the command `kubectl | |
To do so in all your shell sessions, add the following to your `~/.zshrc` file: | |
-```shell | |
+```zsh | |
source <(kubectl completion zsh) | |
``` | |
If you have an alias for kubectl, you can extend shell completion to work with that alias: | |
-```shell | |
+```zsh | |
echo 'alias k=kubectl' >>~/.zshrc | |
echo 'complete -F __start_kubectl k' >>~/.zshrc | |
``` | |
- | |
+ | |
After reloading your shell, kubectl autocompletion should be working. | |
If you get an error like `complete:13: command not found: compdef`, then add the following to the beginning of your `~/.zshrc` file: | |
-```shell | |
+```zsh | |
autoload -Uz compinit | |
compinit | |
``` | |
{{% /tab %}} | |
{{< /tabs >}} | |
-{{% /capture %}} | |
+## {{% heading "whatsnext" %}} | |
-{{% capture whatsnext %}} | |
* [Install Minikube](/docs/tasks/tools/install-minikube/) | |
-* See the [getting started guides](/docs/setup/) for more about creating clusters. | |
+* See the [getting started guides](/docs/setup/) for more about creating clusters. | |
* [Learn how to launch and expose your application.](/docs/tasks/access-application-cluster/service-access-application-cluster/) | |
-* If you need access to a cluster you didn't create, see the [Sharing Cluster Access document](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/). | |
+* If you need access to a cluster you didn't create, see the | |
+ [Sharing Cluster Access document](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/). | |
* Read the [kubectl reference docs](/docs/reference/kubectl/kubectl/) | |
-{{% /capture %}} | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment