Merge pull request #46029 from levi106/linux-kubectl

[ja] Translate content/en/docs/tasks/tools/install-kubectl-linux.md
pull/46187/head
Kubernetes Prow Robot 2024-05-04 16:51:19 -07:00 committed by GitHub
commit babb52f557
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 102 additions and 111 deletions

View File

@ -1,6 +1,6 @@
---
title: "bash auto-completion on Linux"
description: "Some optional configuration for bash auto-completion on Linux."
title: "Linux上でのbashの自動補完"
description: "Linux上でのbashの自動補完に対するいくつかの補助的な設定。"
headless: true
_build:
list: never
@ -8,53 +8,48 @@ _build:
publishResources: false
---
### Introduction
### はじめに
The kubectl completion script for Bash can be generated with the command `kubectl completion bash`.
Sourcing the completion script in your shell enables kubectl autocompletion.
Bashにおけるkubectlの補完スクリプトは`kubectl completion bash`コマンドで生成できます。
補完スクリプトをシェル内に読み込ませることでkubectlの自動補完が有効になります。
However, the completion script depends on
[**bash-completion**](https://github.com/scop/bash-completion),
which means that you have to install this software first
(you can test if you have bash-completion already installed by running `type _init_completion`).
ただし、補完スクリプトは[**bash-completion**](https://github.com/scop/bash-completion)に依存しているため、事前にインストールしておく必要があります(`type _init_completion`を実行することで、bash-completionがすでにインストールされていることを確認できます)。
### Install bash-completion
### bash-completionをインストールする
bash-completion is provided by many package managers
(see [here](https://github.com/scop/bash-completion#installation)).
You can install it with `apt-get install bash-completion` or `yum install bash-completion`, etc.
bash-completionは多くのパッケージマネージャーから提供されています([こちら](https://github.com/scop/bash-completion#installation)を参照してください)。
`apt-get install bash-completion`または`yum install bash-completion`などでインストールできます。
The above commands create `/usr/share/bash-completion/bash_completion`,
which is the main script of bash-completion. Depending on your package manager,
you have to manually source this file in your `~/.bashrc` file.
上記のコマンドでbash-completionの主要スクリプトである`/usr/share/bash-completion/bash_completion`が作成されます。
パッケージマネージャーによっては、このファイルを`~/.bashrc`にて手動で読み込ませる必要があります。
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:
これを調べるには、シェルをリロードしてから`type _init_completion`を実行してください。
コマンドが成功していればすでに設定済みです。そうでなければ、`~/.bashrc`ファイルに以下を追記してください:
```bash
source /usr/share/bash-completion/bash_completion
```
Reload your shell and verify that bash-completion is correctly installed by typing `type _init_completion`.
シェルをリロードし、`type _init_completion`を実行してbash-completionが正しくインストールされていることを検証してください。
### Enable kubectl autocompletion
### kubectlの自動補完を有効にする
#### Bash
You now need to ensure that the kubectl completion script gets sourced in all
your shell sessions. There are two ways in which you can do this:
次に、kubectl補完スクリプトがすべてのシェルセッションで読み込まれるように設定する必要があります。
これを行うには2つの方法があります:
{{< tabs name="kubectl_bash_autocompletion" >}}
{{< tab name="User" codelang="bash" >}}
{{< tab name="ユーザー" codelang="bash" >}}
echo 'source <(kubectl completion bash)' >>~/.bashrc
{{< /tab >}}
{{< tab name="System" codelang="bash" >}}
{{< tab name="システム" codelang="bash" >}}
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
sudo chmod a+r /etc/bash_completion.d/kubectl
{{< /tab >}}
{{< /tabs >}}
If you have an alias for kubectl, you can extend shell completion to work with that alias:
kubectlにエイリアスを張っている場合は、エイリアスでも動作するようにシェルの補完を拡張することができます:
```bash
echo 'alias k=kubectl' >>~/.bashrc
@ -62,11 +57,12 @@ echo 'complete -o default -F __start_kubectl k' >>~/.bashrc
```
{{< note >}}
bash-completion sources all completion scripts in `/etc/bash_completion.d`.
bash-completionは`/etc/bash_completion.d`内のすべての補完スクリプトを読み込みます。
{{< /note >}}
Both approaches are equivalent. After reloading your shell, kubectl autocompletion should be working.
To enable bash autocompletion in current session of shell, source the ~/.bashrc file:
どちらも同様の手法です。
シェルをリロードしたあとに、kubectlの自動補完が機能するはずです。
シェルの現在のセッションでbashの自動補完を有効にするには、~/.bashrcを読み込みます:
```bash
source ~/.bashrc

View File

@ -13,7 +13,7 @@ Fishに対する自動補完はkubectl 1.23以降が必要です。
{{< /note >}}
Fishにおけるkubectlの補完スクリプトは`kubectl completion fish`コマンドで生成できます。
シェル内で補完スクリプトをsourceすることでkubectlの自動補完が有効になります。
補完スクリプトをシェル内に読み込ませることでkubectlの自動補完が有効になります。
すべてのシェルセッションで使用するには、`~/.config/fish/config.fish`に以下を追記してください:

View File

@ -9,7 +9,7 @@ _build:
---
Zshにおけるkubectlの補完スクリプトは`kubectl completion zsh`コマンドで生成できます。
シェル内で補完スクリプトをsourceすることでkubectlの自動補完が有効になります。
補完スクリプトをシェル内に読み込ませることでkubectlの自動補完が有効になります。
すべてのシェルセッションで使用するには、`~/.zshrc`に以下を追記してください:

View File

@ -1,28 +1,26 @@
---
title: Install and Set Up kubectl on Linux
title: Linux上でのkubectlのインストールおよびセットアップ
content_type: task
weight: 10
---
## {{% heading "prerequisites" %}}
You must use a kubectl version that is within one minor version difference of
your cluster. For example, a v{{< skew currentVersion >}} client can communicate
with v{{< skew currentVersionAddMinor -1 >}}, v{{< skew currentVersionAddMinor 0 >}},
and v{{< skew currentVersionAddMinor 1 >}} control planes.
Using the latest compatible version of kubectl helps avoid unforeseen issues.
kubectlのバージョンは、クラスターのマイナーバージョンとの差分が1つ以内でなければなりません。
たとえば、クライアントがv{{< skew currentVersion >}}であれば、v{{< skew currentVersionAddMinor -1 >}}、v{{< skew currentVersionAddMinor 0 >}}、v{{< skew currentVersionAddMinor 1 >}}のコントロールプレーンと通信できます。
最新の互換性のあるバージョンのkubectlを使うことで、不測の事態を避けることができるでしょう。
## Install kubectl on Linux
## Linuxへkubectlをインストールする
The following methods exist for installing kubectl on Linux:
Linuxへkubectlをインストールするには、次の方法があります:
- [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)
- [curlを使用してLinuxへkubectlのバイナリをインストールする](#install-kubectl-binary-with-curl-on-linux)
- [ネイティブなパッケージマネージャーを使用してインストールする](#install-using-native-package-management)
- [他のパッケージマネージャーを使用してインストールする](#install-using-other-package-management)
### Install kubectl binary with curl on Linux
### curlを使用してLinuxへkubectlのバイナリをインストールする{#install-kubectl-binary-with-curl-on-linux}
1. Download the latest release with the command:
1. 次のコマンドにより、最新リリースをダウンロードしてください:
{{< tabs name="download_binary_linux" >}}
{{< tab name="x86-64" codelang="bash" >}}
@ -34,16 +32,15 @@ The following methods exist for installing kubectl on Linux:
{{< /tabs >}}
{{< 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.
特定のバージョンをダウンロードする場合、コマンドの`$(curl -L -s https://dl.k8s.io/release/stable.txt)`の部分を特定のバージョンに書き換えてください。
For example, to download version {{< skew currentPatchVersion >}} on Linux x86-64, type:
たとえば、Linux x86-64へ{{< skew currentPatchVersion >}}のバージョンをダウンロードするには、次のコマンドを入力します:
```bash
curl -LO https://dl.k8s.io/release/v{{< skew currentPatchVersion >}}/bin/linux/amd64/kubectl
```
And for Linux ARM64, type:
そして、Linux ARM64に対しては、次のコマンドを入力します:
```bash
curl -LO https://dl.k8s.io/release/v{{< skew currentPatchVersion >}}/bin/linux/arm64/kubectl
@ -51,9 +48,9 @@ The following methods exist for installing kubectl on Linux:
{{< /note >}}
1. Validate the binary (optional)
1. バイナリを検証してください(オプション)
Download the kubectl checksum file:
kubectlのチェックサムファイルをダウンロードします:
{{< tabs name="download_checksum_linux" >}}
{{< tab name="x86-64" codelang="bash" >}}
@ -64,19 +61,19 @@ The following methods exist for installing kubectl on Linux:
{{< /tab >}}
{{< /tabs >}}
Validate the kubectl binary against the checksum file:
チェックサムファイルに対してkubectlバイナリを検証します:
```bash
echo "$(cat 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:
チェックに失敗すると、`sha256`は0以外のステータスで終了し、次のような出力を表示します:
```console
kubectl: FAILED
@ -84,78 +81,81 @@ The following methods exist for installing kubectl on Linux:
```
{{< note >}}
Download the same version of the binary and checksum.
同じバージョンのバイナリとチェックサムをダウンロードしてください。
{{< /note >}}
1. Install kubectl
1. 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:
ターゲットシステムにルートアクセスを持っていない場合でも、`~/.local/bin`ディレクトリにkubectlをインストールできます:
```bash
chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin/kubectl
# and then append (or prepend) ~/.local/bin to $PATH
# そして ~/.local/bin を $PATH の末尾 (または先頭) に追加します
```
{{< /note >}}
1. Test to ensure the version you installed is up-to-date:
1. インストールしたバージョンが最新であることを確認してください:
```bash
kubectl version --client
```
Or use this for detailed view of version:
または、バージョンの詳細を表示するために次を使用します:
```cmd
kubectl version --client --output=yaml
```
### Install using native package management
### ネイティブなパッケージマネージャーを使用してインストールする{#install-using-native-package-management}
{{< tabs name="kubectl_install" >}}
{{% tab name="Debian-based distributions" %}}
{{% tab name="Debianベースのディストリビューション" %}}
1. Update the `apt` package index and install packages needed to use the Kubernetes `apt` repository:
1. `apt`のパッケージ一覧を更新し、Kubernetesの`apt`リポジトリを利用するのに必要なパッケージをインストールしてください:
```shell
sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
# apt-transport-httpsはダミーパッケージの可能性があります。その場合、そのパッケージはスキップできます
sudo apt-get install -y apt-transport-https ca-certificates curl
```
2. Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:
2. Kubernetesパッケージリポジトリの公開署名キーをダウンロードしてください。
すべてのリポジトリに同じ署名キーが使用されるため、URL内のバージョンは無視できます:
```shell
# If the folder `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below.
# `/etc/apt/keyrings`フォルダーが存在しない場合は、curlコマンドの前に作成する必要があります。下記の備考を参照してください。
# sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/{{< param "version" >}}/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg # 特権のないAPTプログラムがこのkeyringを読めるようにします
```
{{< note >}}
In releases older than Debian 12 and Ubuntu 22.04, folder `/etc/apt/keyrings` does not exist by default, and it should be created before the curl command.
Debian 12とUbuntu 22.04より古いリリースでは、`/etc/apt/keyrings`フォルダーは既定では存在しないため、curlコマンドの前に作成する必要があります。
{{< /note >}}
3. Add the appropriate Kubernetes `apt` repository. If you want to use Kubernetes version different than {{< param "version" >}},
replace {{< param "version" >}} with the desired minor version in the command below:
3. 適切なKubernetesの`apt`リポジトリを追加してください。
{{< param "version" >}}とは異なるKubernetesバージョンを利用したい場合は、以下のコマンドの{{< param "version" >}}を目的のマイナーバージョンに置き換えてください:
```shell
# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
# これにより、/etc/apt/sources.list.d/kubernetes.listにある既存の設定が上書きされます
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/{{< param "version" >}}/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list # command-not-foundのようなツールが正しく動作するようにします
```
{{< note >}}
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/apt/sources.list.d/kubernetes.list` before running `apt-get update` and `apt-get upgrade`. This procedure is described in more detail in [Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
kubectlを他のマイナーリリースにアップグレードするためには、`apt-get update`と`apt-get upgrade`を実行する前に、`/etc/apt/sources.list.d/kubernetes.list`の中のバージョンを上げる必要があります。
この手順については[Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/)に詳細が記載されています。
{{< /note >}}
4. Update `apt` package index, then install kubectl:
4. `apt`のパッケージインデックスを更新し、kubectlをインストールしてください:
```shell
sudo apt-get update
@ -164,14 +164,13 @@ To upgrade kubectl to another minor release, you'll need to bump the version in
{{% /tab %}}
{{% tab name="Red Hat-based distributions" %}}
{{% tab name="Red Hatベースのディストリビューション" %}}
1. Add the Kubernetes `yum` repository. If you want to use Kubernetes version
different than {{< param "version" >}}, replace {{< param "version" >}} with
the desired minor version in the command below.
1. Kubernetesの`yum`リポジトリを追加してください。
{{< param "version" >}}とは異なるKubernetesバージョンを利用したい場合は、以下のコマンドの{{< param "version" >}}を目的のマイナーバージョンに置き換えてください:
```bash
# This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
# これにより、/etc/yum.repos.d/kubernetes.repoにある既存の設定が上書きされます
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
@ -183,10 +182,11 @@ To upgrade kubectl to another minor release, you'll need to bump the version in
```
{{< note >}}
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/yum.repos.d/kubernetes.repo` before running `yum update`. This procedure is described in more detail in [Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
kubectlを他のマイナーリリースにアップグレードするためには、`yum update`を実行する前に、`/etc/yum.repos.d/kubernetes.repo`の中のバージョンを上げる必要があります。
この手順については[Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/)に詳細が記載されています。
{{< /note >}}
2. Install kubectl using `yum`:
2. `yum`を使用してkubectlをインストールしてください:
```bash
sudo yum install -y kubectl
@ -194,14 +194,13 @@ To upgrade kubectl to another minor release, you'll need to bump the version in
{{% /tab %}}
{{% tab name="SUSE-based distributions" %}}
{{% tab name="SUSEベースのディストリビューション" %}}
1. Add the Kubernetes `zypper` repository. If you want to use Kubernetes version
different than {{< param "version" >}}, replace {{< param "version" >}} with
the desired minor version in the command below.
1. Kubernetesの`zypper`リポジトリを追加してください。
{{< param "version" >}}とは異なるKubernetesバージョンを利用したい場合は、以下のコマンドの{{< param "version" >}}を目的のマイナーバージョンに置き換えてください。
```bash
# This overwrites any existing configuration in /etc/zypp/repos.d/kubernetes.repo
# これにより、/etc/zypp/repos.d/kubernetes.repoにある既存の設定が上書きされます
cat <<EOF | sudo tee /etc/zypp/repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
@ -213,12 +212,11 @@ To upgrade kubectl to another minor release, you'll need to bump the version in
```
{{< note >}}
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/zypp/repos.d/kubernetes.repo`
before running `zypper update`. This procedure is described in more detail in
[Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
kubectlを他のマイナーリリースにアップグレードするためには、`zypper update`を実行する前に、`/etc/zypp/repos.d/kubernetes.repo`の中のバージョンを上げる必要があります。
この手順については[Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/)に詳細が記載されています。
{{< /note >}}
2. Install kubectl using `zypper`:
2. `zypper`を使用してkubectlをインストールしてください:
```bash
sudo zypper install -y kubectl
@ -227,13 +225,11 @@ before running `zypper update`. This procedure is described in more detail in
{{% /tab %}}
{{< /tabs >}}
### Install using other package management
### 他のパッケージマネージャーを使用してインストールする{#install-using-other-package-management}
{{< tabs name="other_kubectl_install" >}}
{{% tab name="Snap" %}}
If you are on Ubuntu or another Linux distribution that supports the
[snap](https://snapcraft.io/docs/core/install) package manager, kubectl
is available as a [snap](https://snapcraft.io/) application.
Ubuntuまたは[snap](https://snapcraft.io/docs/core/install)パッケージマネージャーをサポートする別のLinuxディストリビューションを使用している場合、kubectlは[snap](https://snapcraft.io/)アプリケーションとして使用できます。
```shell
snap install kubectl --classic
@ -243,8 +239,7 @@ 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).
Linuxで[Homebrew](https://docs.brew.sh/Homebrew-on-Linux)パッケージマネージャーを使用している場合は、kubectlを[インストール](https://docs.brew.sh/Homebrew-on-Linux#install)することが可能です。
```shell
brew install kubectl
@ -255,18 +250,18 @@ kubectl version --client
{{< /tabs >}}
## Verify kubectl configuration
## kubectlの設定を検証する
{{< include "included/verify-kubectl.md" >}}
## Optional kubectl configurations and plugins
## オプションのkubectlの設定とプラグイン
### Enable shell autocompletion
### シェルの自動補完を有効にする
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell,
which can save you a lot of typing.
kubectlはBash、Zsh、Fish、PowerShellの自動補完を提供しています。
これにより、入力を大幅に削減することができます。
Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
以下にBash、Fish、Zshの自動補完の設定手順を示します。
{{< tabs name="kubectl_autocompletion" >}}
{{< tab name="Bash" include="included/optional-kubectl-configs-bash-linux.md" />}}
@ -274,11 +269,11 @@ Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}}
{{< /tabs >}}
### Install `kubectl convert` plugin
### `kubectl convert`プラグインをインストールする
{{< include "included/kubectl-convert-overview.md" >}}
1. Download the latest release with the command:
1. 次のコマンドを使用して最新リリースをダウンロードしてください:
{{< tabs name="download_convert_binary_linux" >}}
{{< tab name="x86-64" codelang="bash" >}}
@ -289,9 +284,9 @@ Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
{{< /tab >}}
{{< /tabs >}}
1. Validate the binary (optional)
1. バイナリを検証してください(オプション)
Download the kubectl-convert checksum file:
kubectl-convertのチェックサムファイルをダウンロードします:
{{< tabs name="download_convert_checksum_linux" >}}
{{< tab name="x86-64" codelang="bash" >}}
@ -302,19 +297,19 @@ Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
{{< /tab >}}
{{< /tabs >}}
Validate the kubectl-convert binary against the checksum file:
チェックサムファイルに対してkubectl-convertバイナリを検証します:
```bash
echo "$(cat kubectl-convert.sha256) kubectl-convert" | sha256sum --check
```
If valid, the output is:
正しければ、出力は次のようになります:
```console
kubectl-convert: OK
```
If the check fails, `sha256` exits with nonzero status and prints output similar to:
チェックに失敗すると、`sha256`は0以外のステータスで終了し、次のような出力を表示します:
```console
kubectl-convert: FAILED
@ -322,24 +317,24 @@ Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
```
{{< note >}}
Download the same version of the binary and checksum.
同じバージョンのバイナリとチェックサムをダウンロードしてください。
{{< /note >}}
1. Install kubectl-convert
1. kubectl-convertをインストールしてください
```bash
sudo install -o root -g root -m 0755 kubectl-convert /usr/local/bin/kubectl-convert
```
1. Verify plugin is successfully installed
1. プラグインが正常にインストールできたことを確認してください
```shell
kubectl convert --help
```
If you do not see an error, it means the plugin is successfully installed.
何もエラーが表示されない場合は、プラグインが正常にインストールされたことを示しています。
1. After installing the plugin, clean up the installation files:
1. プラグインのインストール後、インストールファイルを削除してください:
```bash
rm kubectl-convert kubectl-convert.sha256