Merge pull request #21719 from sftim/20200613_revise_kubectl_installation_task

Revise kubectl installation task
This commit is contained in:
Kubernetes Prow Robot 2020-06-15 12:25:57 -07:00 committed by GitHub
commit dada2d0767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 121 additions and 120 deletions

View File

@ -114,7 +114,7 @@ kubectl version --client
1. Download the latest release:
```
```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"
```
@ -122,25 +122,25 @@ kubectl version --client
For example, to download version {{< param "fullversion" >}} on macOS, type:
```
```bash
curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl
```
2. Make the kubectl binary executable.
Make the kubectl binary executable.
```
```bash
chmod +x ./kubectl
```
3. Move the binary in to your PATH.
```
```bash
sudo mv ./kubectl /usr/local/bin/kubectl
```
4. Test to ensure the version you installed is up-to-date:
```
```bash
kubectl version --client
```
@ -150,19 +150,19 @@ If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you
1. Run the installation command:
```
```bash
brew install kubectl
```
or
```
```bash
brew install kubernetes-cli
```
2. Test to ensure the version you installed is up-to-date:
```
```bash
kubectl version --client
```
@ -172,14 +172,14 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
1. Run the installation command:
```
```bash
sudo port selfupdate
sudo port install kubectl
```
2. Test to ensure the version you installed is up-to-date:
```
```bash
kubectl version --client
```
@ -191,7 +191,7 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
Or if you have `curl` installed, use this command:
```
```bash
curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe
```
@ -201,7 +201,7 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
3. Test to ensure the version of `kubectl` is the same as downloaded:
```
```bash
kubectl version --client
```
@ -216,19 +216,20 @@ If you are on Windows and using [Powershell Gallery](https://www.powershellgalle
1. Run the installation commands (making sure to specify a `DownloadLocation`):
```
Install-Script -Name install-kubectl -Scope CurrentUser -Force
```powershell
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 >}}
{{< 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:
```
```powershell
kubectl version --client
```
@ -240,50 +241,54 @@ Updating the installation is performed by rerunning the two commands listed in s
1. 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" %}}
{{< tabs name="kubectl_win_install" >}}
{{% tab name="choco" %}}
```powershell
choco install kubernetes-cli
{{% /tab %}}
{{% tab name="scoop" %}}
```
{{% /tab %}}
{{% tab name="scoop" %}}
```powershell
scoop install kubectl
{{% /tab %}}
{{< /tabs >}}
```
{{% /tab %}}
{{< /tabs >}}
2. Test to ensure the version you installed is up-to-date:
```
```powershell
kubectl version --client
```
3. Navigate to your home directory:
```powershell
# If you're using cmd.exe, run: cd %USERPROFILE%
cd ~
```
cd %USERPROFILE%
```
4. Create the `.kube` directory:
```
```powershell
mkdir .kube
```
5. Change to the `.kube` directory you just created:
```
```powershell
cd .kube
```
6. Configure kubectl to use a remote Kubernetes cluster:
```
```powershell
New-Item config -type file
```
{{< note >}}Edit the config file with a text editor of your choice, such as Notepad.{{< /note >}}
{{< note >}}
Edit the config file with a text editor of your choice, such as Notepad.
{{< /note >}}
## Download as part of the Google Cloud SDK
@ -293,13 +298,13 @@ You can install kubectl as part of the Google Cloud SDK.
2. Run the `kubectl` installation command:
```
```shell
gcloud components install kubectl
```
3. Test to ensure the version you installed is up-to-date:
```
```shell
kubectl version --client
```
@ -317,7 +322,7 @@ If you see a URL response, kubectl is correctly configured to access your cluste
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?
```
@ -355,7 +360,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
```
@ -367,17 +372,17 @@ You now need to ensure that the kubectl completion script gets sourced in all yo
- Source the completion script in your `~/.bashrc` file:
```shell
```bash
echo 'source <(kubectl completion bash)' >>~/.bashrc
```
- Add the completion script to the `/etc/bash_completion.d` directory:
```shell
```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
```bash
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.bashrc
```
@ -408,19 +413,19 @@ There are two versions of bash-completion, v1 and v2. V1 is for Bash 3.2 (which
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
```
@ -434,13 +439,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 `~/.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"
```
@ -453,20 +458,20 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
- Source the completion script in your `~/.bash_profile` file:
```shell
```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
```bash
echo 'alias k=kubectl' >>~/.bash_profile
echo 'complete -F __start_kubectl k' >>~/.bash_profile
```
@ -486,13 +491,13 @@ 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
```
@ -501,16 +506,13 @@ 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 >}}
## {{% heading "whatsnext" %}}
* [Install Minikube](/docs/tasks/tools/install-minikube/)
@ -518,4 +520,3 @@ compinit
* [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/).
* Read the [kubectl reference docs](/docs/reference/kubectl/kubectl/)