Revise kubectl installation task

This commit is contained in:
Tim Bannister
2020-06-13 23:04:47 +01:00
parent aa193415cc
commit 117d0d6422
+121 -120
View File
@@ -114,35 +114,35 @@ kubectl version --client
1. Download the latest release: 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" 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: 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
```
2. Make the kubectl binary executable. ```bash
curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl
```
``` Make the kubectl binary executable.
chmod +x ./kubectl
``` ```bash
chmod +x ./kubectl
```
3. Move the binary in to your PATH. 3. Move the binary in to your PATH.
``` ```bash
sudo mv ./kubectl /usr/local/bin/kubectl sudo mv ./kubectl /usr/local/bin/kubectl
``` ```
4. Test to ensure the version you installed is up-to-date: 4. Test to ensure the version you installed is up-to-date:
``` ```bash
kubectl version --client kubectl version --client
``` ```
### Install with Homebrew on macOS ### Install with Homebrew on macOS
@@ -150,21 +150,21 @@ If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you
1. Run the installation command: 1. Run the installation command:
``` ```bash
brew install kubectl brew install kubectl
``` ```
or or
``` ```bash
brew install kubernetes-cli brew install kubernetes-cli
``` ```
2. Test to ensure the version you installed is up-to-date: 2. Test to ensure the version you installed is up-to-date:
``` ```bash
kubectl version --client kubectl version --client
``` ```
### Install with Macports on macOS ### Install with Macports on macOS
@@ -172,16 +172,16 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
1. Run the installation command: 1. Run the installation command:
``` ```bash
sudo port selfupdate sudo port selfupdate
sudo port install kubectl sudo port install kubectl
``` ```
2. Test to ensure the version you installed is up-to-date: 2. Test to ensure the version you installed is up-to-date:
``` ```bash
kubectl version --client kubectl version --client
``` ```
## Install kubectl on Windows ## Install kubectl on Windows
@@ -189,21 +189,21 @@ 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). 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:
``` ```bash
curl -LO https://storage.googleapis.com/kubernetes-release/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe 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. 2. Add the binary in to your PATH.
3. Test to ensure the version of `kubectl` is the same as downloaded: 3. Test to ensure the version of `kubectl` is the same as downloaded:
``` ```bash
kubectl version --client kubectl version --client
``` ```
{{< note >}} {{< note >}}
[Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/#kubernetes) adds its own version of `kubectl` to PATH. [Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/#kubernetes) adds its own version of `kubectl` to PATH.
@@ -216,21 +216,22 @@ If you are on Windows and using [Powershell Gallery](https://www.powershellgalle
1. Run the installation commands (making sure to specify a `DownloadLocation`): 1. Run the installation commands (making sure to specify a `DownloadLocation`):
``` ```powershell
Install-Script -Name install-kubectl -Scope CurrentUser -Force Install-Script -Name 'install-kubectl' -Scope CurrentUser -Force
install-kubectl.ps1 [-DownloadLocation <path>] 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. 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: 2. Test to ensure the version you installed is up-to-date:
``` ```powershell
kubectl version --client kubectl version --client
``` ```
{{< note >}} {{< note >}}
Updating the installation is performed by rerunning the two commands listed in step 1. Updating the installation is performed by rerunning the two commands listed in step 1.
@@ -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. 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" >}} {{< tabs name="kubectl_win_install" >}}
{{% tab name="choco" %}} {{% tab name="choco" %}}
```powershell
choco install kubernetes-cli choco install kubernetes-cli
```
{{% /tab %}} {{% /tab %}}
{{% tab name="scoop" %}} {{% tab name="scoop" %}}
```powershell
scoop install kubectl scoop install kubectl
```
{{% /tab %}} {{% /tab %}}
{{< /tabs >}} {{< /tabs >}}
2. Test to ensure the version you installed is up-to-date: 2. Test to ensure the version you installed is up-to-date:
``` ```powershell
kubectl version --client kubectl version --client
``` ```
3. Navigate to your home directory: 3. Navigate to your home directory:
``` ```powershell
cd %USERPROFILE% # If you're using cmd.exe, run: cd %USERPROFILE%
``` cd ~
```
4. Create the `.kube` directory: 4. Create the `.kube` directory:
``` ```powershell
mkdir .kube mkdir .kube
``` ```
5. Change to the `.kube` directory you just created: 5. Change to the `.kube` directory you just created:
``` ```powershell
cd .kube cd .kube
``` ```
6. Configure kubectl to use a remote Kubernetes cluster: 6. Configure kubectl to use a remote Kubernetes cluster:
``` ```powershell
New-Item config -type file 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 ## Download as part of the Google Cloud SDK
@@ -293,17 +298,17 @@ You can install kubectl as part of the Google Cloud SDK.
2. Run the `kubectl` installation command: 2. Run the `kubectl` installation command:
``` ```shell
gcloud components install kubectl gcloud components install kubectl
``` ```
3. Test to ensure the version you installed is up-to-date: 3. Test to ensure the version you installed is up-to-date:
``` ```shell
kubectl version --client 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/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`.
@@ -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. 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? 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: 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 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: - Source the completion script in your `~/.bashrc` file:
```shell ```bash
echo 'source <(kubectl completion bash)' >>~/.bashrc echo 'source <(kubectl completion bash)' >>~/.bashrc
``` ```
- Add the completion script to the `/etc/bash_completion.d` directory: - Add the completion script to the `/etc/bash_completion.d` directory:
```shell ```bash
kubectl completion bash >/etc/bash_completion.d/kubectl 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: 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 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.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: The instructions here assume you use Bash 4.1+. You can check your Bash's version by running:
```shell ```bash
echo $BASH_VERSION echo $BASH_VERSION
``` ```
If it is too old, you can install/upgrade it using Homebrew: If it is too old, you can install/upgrade it using Homebrew:
```shell ```bash
brew install bash brew install bash
``` ```
Reload your shell and verify that the desired version is being used: Reload your shell and verify that the desired version is being used:
```shell ```bash
echo $BASH_VERSION $SHELL 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: 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 brew install bash-completion@2
``` ```
As stated in the output of this command, add the following to your `~/.bash_profile` 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" 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" [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
``` ```
@@ -453,29 +458,29 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
- Source the completion script in your `~/.bash_profile` file: - Source the completion script in your `~/.bash_profile` file:
```shell ```bash
echo 'source <(kubectl completion bash)' >>~/.bash_profile echo 'source <(kubectl completion bash)' >>~/.bash_profile
``` ```
- Add the completion script to the `/usr/local/etc/bash_completion.d` directory: - 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 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: - 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 'alias k=kubectl' >>~/.bash_profile
echo 'complete -F __start_kubectl k' >>~/.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. - 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 >}} {{< 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. 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 >}}
In any case, after reloading your shell, kubectl completion should be working. In any case, after reloading your shell, kubectl completion should be working.
{{% /tab %}} {{% /tab %}}
@@ -486,36 +491,32 @@ 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: To do so in all your shell sessions, add the following to your `~/.zshrc` file:
```shell ```zsh
source <(kubectl completion zsh) source <(kubectl completion zsh)
``` ```
If you have an alias for kubectl, you can extend shell completion to work with that alias: 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 'alias k=kubectl' >>~/.zshrc
echo 'complete -F __start_kubectl k' >>~/.zshrc echo 'complete -F __start_kubectl k' >>~/.zshrc
``` ```
After reloading your shell, kubectl autocompletion should be working. 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: 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 autoload -Uz compinit
compinit compinit
``` ```
{{% /tab %}} {{% /tab %}}
{{< /tabs >}} {{< /tabs >}}
## {{% heading "whatsnext" %}} ## {{% heading "whatsnext" %}}
* [Install Minikube](/docs/tasks/tools/install-minikube/) * [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/) * [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/) * Read the [kubectl reference docs](/docs/reference/kubectl/kubectl/)