ツールのインストール
Kubernetesのツールをローカルのコンピューター上にセットアップします。
kubectl
Kubernetesのコマンドラインツールkubectl
を使用すると、Kubernetesクラスターに対してコマンドを実行できるようになります。kubectlは、アプリケーションのデプロイ、クラスターリソースの調査と管理、ログの表示などに使用できます。
kubectl
のダウンロードとインストールを行い、クラスターへのアクセスをセットアップする方法については、kubectlのインストールおよびセットアップを参照してください。
また、kubectl
リファレンスドキュメントも参照できます。
minikube
minikubeは、Kubernetesをローカルで実行するツールです。minikubeはシングルノードのKubernetesクラスターをパーソナルコンピューター上(Windows、macOS、Linux PCを含む)で実行することで、Kubernetesを試したり、日常的な開発作業のために利用できます。
ツールのインストールについて知りたい場合は、公式のGet Started!のガイドに従ってください。
minikubeが起動したら、サンプルアプリケーションの実行を試すことができます。
kind
minikubeと同じように、kindもローカルコンピューター上でKubernetesを実行するツールです。minikubeとは違い、kindは1種類のコンテナランタイム上でしか動作しません。実行にはDockerのインストールと設定が必要です。
Quick Startに、kindの起動に必要な手順が説明されています。
1 - Install and Set Up kubectl on Linux
始める前に
You must use a kubectl version that is within one minor version difference of
your cluster. For example, a v1.30 client can communicate
with v1.29, v1.30,
and v1.31 control planes.
Using the latest compatible 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
-
Download the latest release with the command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl"
備考: 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 1.30.0 on Linux x86-64, type:
curl -LO https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl
And for Linux ARM64, type:
curl -LO https://dl.k8s.io/release/v1.30.0/bin/linux/arm64/kubectl
-
Validate the binary (optional)
Download the kubectl checksum file:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl.sha256"
Validate the kubectl binary against the checksum file:
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
If valid, the output is:
If the check fails, sha256
exits with nonzero status and prints output similar to:
kubectl: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
備考: Download the same version of the binary and checksum.
-
Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
備考: If you do not have root access on the target system, you can still install
kubectl to the ~/.local/bin
directory:
chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin/kubectl
# and then append (or prepend) ~/.local/bin to $PATH
-
Test to ensure the version you installed is up-to-date:
Or use this for detailed view of version:
kubectl version --client --output=yaml
Install using native package management
-
Update the apt
package index and install packages needed to use the Kubernetes apt
repository:
sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl
-
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:
# If the folder `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below.
# sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
備考: 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.
-
Add the appropriate Kubernetes apt
repository. If you want to use Kubernetes version different than v1.30,
replace v1.30 with the desired minor version in the command below:
# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
備考: 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.
-
Update apt
package index, then install kubectl:
sudo apt-get update
sudo apt-get install -y kubectl
-
Add the Kubernetes yum
repository. If you want to use Kubernetes version
different than v1.30, replace v1.30 with
the desired minor version in the command below.
# This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/repodata/repomd.xml.key
EOF
備考: 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.
-
Install kubectl using yum
:
sudo yum install -y kubectl
-
Add the Kubernetes zypper
repository. If you want to use Kubernetes version
different than v1.30, replace v1.30 with
the desired minor version in the command below.
# This overwrites any existing configuration in /etc/zypp/repos.d/kubernetes.repo
cat <<EOF | sudo tee /etc/zypp/repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/repodata/repomd.xml.key
EOF
備考: 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.
-
Install kubectl using zypper
:
sudo zypper install -y kubectl
Install using other package management
If you are on Ubuntu or another Linux distribution that supports the
snap package manager, kubectl
is available as a snap application.
snap install kubectl --classic
kubectl version --client
If you are on Linux and using Homebrew
package manager, kubectl is available for installation.
brew install kubectl
kubectl version --client
Verify kubectl configuration
kubectlがKubernetesクラスターを探索し接続するために、kubeconfigファイルが必要です。
これは、kube-up.shによりクラスターを作成した際や、Minikubeクラスターを正常にデプロイした際に自動生成されます。
デフォルトでは、kubectlの設定は~/.kube/config
に格納されています。
クラスターの状態を取得し、kubectlが適切に設定されていることを確認してください:
URLのレスポンスが表示されている場合は、kubectlはクラスターに接続するよう正しく設定されています。
以下のようなメッセージが表示されている場合は、kubectlは正しく設定されていないか、Kubernetesクラスターに接続できていません。
The connection to the server <server-name:port> was refused - did you specify the right host or port?
たとえば、ラップトップ上(ローカル環境)でKubernetesクラスターを起動するような場合、Minikubeなどのツールを最初にインストールしてから、上記のコマンドを再実行する必要があります。
kubectl cluster-info
がURLレスポンスを返したにもかかわらずクラスターにアクセスできない場合は、次のコマンドで設定が正しいことを確認してください:
kubectl cluster-info dump
エラーメッセージ'No Auth Provider Found'のトラブルシューティング
Kubernetes 1.26にて、kubectlは以下のクラウドプロバイダーが提供するマネージドKubernetesのビルトイン認証を削除しました。
これらのプロバイダーは、クラウド固有の認証を提供するkubectlプラグインをリリースしています。
手順については以下のプロバイダーのドキュメントを参照してください:
(この変更とは関係なく、他の理由で同じエラーメッセージが表示される可能性もあります。)
Optional kubectl configurations and plugins
Enable shell autocompletion
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell,
which can save you a lot of typing.
Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
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.
However, the completion script depends on
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
).
Install bash-completion
bash-completion is provided by many package managers
(see here).
You can install it with apt-get install bash-completion
or yum install bash-completion
, etc.
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.
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:
source /usr/share/bash-completion/bash_completion
Reload your shell and verify that bash-completion is correctly installed by typing type _init_completion
.
Enable kubectl autocompletion
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:
echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
sudo chmod a+r /etc/bash_completion.d/kubectl
If you have an alias for kubectl, you can extend shell completion to work with that alias:
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -o default -F __start_kubectl k' >>~/.bashrc
備考: bash-completion sources all completion scripts in /etc/bash_completion.d
.
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:
備考: Fishに対する自動補完はkubectl 1.23以降が必要です。
Fishにおけるkubectlの補完スクリプトはkubectl completion fish
コマンドで生成できます。
シェル内で補完スクリプトをsourceすることでkubectlの自動補完が有効になります。
すべてのシェルセッションで使用するには、~/.config/fish/config.fish
に以下を追記してください:
kubectl completion fish | source
シェルをリロードしたあとに、kubectlの自動補完が機能するはずです。
Zshにおけるkubectlの補完スクリプトはkubectl completion zsh
コマンドで生成できます。
シェル内で補完スクリプトをsourceすることでkubectlの自動補完が有効になります。
すべてのシェルセッションで使用するには、~/.zshrc
に以下を追記してください:
source <(kubectl completion zsh)
kubectlにエイリアスを張っている場合でも、kubectlの自動補完は自動的に機能します。
シェルをリロードしたあとに、kubectlの自動補完が機能するはずです。
2: command not found: compdef
のようなエラーが出力された場合は、以下を~/.zshrc
の先頭に追記してください:
autoload -Uz compinit
compinit
Install kubectl convert
plugin
異なるAPIバージョン間でマニフェストを変換できる、Kubernetesコマンドラインツールkubectl
のプラグインです。
これは特に、新しいKubernetesのリリースで、非推奨ではないAPIバージョンにマニフェストを移行する場合に役に立ちます。
詳細については非推奨ではないAPIへの移行を参照してください。
-
Download the latest release with the command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl-convert"
-
Validate the binary (optional)
Download the kubectl-convert checksum file:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert.sha256"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl-convert.sha256"
Validate the kubectl-convert binary against the checksum file:
echo "$(cat kubectl-convert.sha256) kubectl-convert" | sha256sum --check
If valid, the output is:
If the check fails, sha256
exits with nonzero status and prints output similar to:
kubectl-convert: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
備考: Download the same version of the binary and checksum.
-
Install kubectl-convert
sudo install -o root -g root -m 0755 kubectl-convert /usr/local/bin/kubectl-convert
-
Verify plugin is successfully installed
If you do not see an error, it means the plugin is successfully installed.
-
After installing the plugin, clean up the installation files:
rm kubectl-convert kubectl-convert.sha256
次の項目
2 - macOS上でのkubectlのインストールおよびセットアップ
始める前に
kubectlのバージョンは、クラスターのマイナーバージョンとの差分が1つ以内でなければなりません。
たとえば、クライアントがv1.30であれば、v1.29、v1.30、v1.31のコントロールプレーンと通信できます。
最新の互換性のあるバージョンのkubectlを使うことで、不測の事態を避けることができるでしょう。
macOSへkubectlをインストールする
macOSへkubectlをインストールするには、次の方法があります:
curlを使用してmacOSへkubectlのバイナリをインストールする
-
最新リリースをダウンロードしてください:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"
備考: 特定のバージョンをダウンロードする場合、コマンドの$(curl -L -s https://dl.k8s.io/release/stable.txt)
の部分を特定のバージョンに置き換えてください。
例えば、Intel macOSへ1.30.0のバージョンをダウンロードするには、次のコマンドを入力します:
curl -LO "https://dl.k8s.io/release/v1.30.0/bin/darwin/amd64/kubectl"
Appleシリコン上のmacOSに対しては、次を入力します:
curl -LO "https://dl.k8s.io/release/v1.30.0/bin/darwin/arm64/kubectl"
-
バイナリを検証してください(オプション)
kubectlのチェックサムファイルをダウンロードします:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl.sha256"
チェックサムファイルに対してkubectlバイナリを検証します:
echo "$(cat kubectl.sha256) kubectl" | shasum -a 256 --check
正しければ、出力は次のようになります:
チェックに失敗すると、shasum
は0以外のステータスで終了し、次のような出力を表示します:
kubectl: FAILED
shasum: WARNING: 1 computed checksum did NOT match
備考: 同じバージョンのバイナリとチェックサムをダウンロードしてください。
-
kubectlバイナリを実行可能にしてください。
-
kubectlバイナリをPATH
の中に移動させてください。
sudo mv ./kubectl /usr/local/bin/kubectl
sudo chown root: /usr/local/bin/kubectl
備考: /usr/local/bin
がPATH環境変数の中に含まれるようにしてください。
-
インストールしたバージョンが最新であることを確認してください:
または、バージョンの詳細を表示するために次を使用します:
kubectl version --client --output=yaml
-
kubectlをインストールし、検証した後は、チェックサムファイルを削除してください:
Homebrewを使用してmacOSへインストールする
macOSでHomebrewパッケージマネージャーを使用していれば、Homebrewでkubectlをインストールできます。
-
インストールコマンドを実行してください:
または
brew install kubernetes-cli
-
インストールしたバージョンが最新であることを確認してください:
MacPortsを使用してmacOSへインストールする
macOSでMacPortsパッケージマネージャーを使用していれば、MacPortsでkubectlをインストールできます。
-
インストールコマンドを実行してください:
sudo port selfupdate
sudo port install kubectl
-
インストールしたバージョンが最新であることを確認してください:
kubectlの設定を検証する
kubectlがKubernetesクラスターを探索し接続するために、kubeconfigファイルが必要です。
これは、kube-up.shによりクラスターを作成した際や、Minikubeクラスターを正常にデプロイした際に自動生成されます。
デフォルトでは、kubectlの設定は~/.kube/config
に格納されています。
クラスターの状態を取得し、kubectlが適切に設定されていることを確認してください:
URLのレスポンスが表示されている場合は、kubectlはクラスターに接続するよう正しく設定されています。
以下のようなメッセージが表示されている場合は、kubectlは正しく設定されていないか、Kubernetesクラスターに接続できていません。
The connection to the server <server-name:port> was refused - did you specify the right host or port?
たとえば、ラップトップ上(ローカル環境)でKubernetesクラスターを起動するような場合、Minikubeなどのツールを最初にインストールしてから、上記のコマンドを再実行する必要があります。
kubectl cluster-info
がURLレスポンスを返したにもかかわらずクラスターにアクセスできない場合は、次のコマンドで設定が正しいことを確認してください:
kubectl cluster-info dump
エラーメッセージ'No Auth Provider Found'のトラブルシューティング
Kubernetes 1.26にて、kubectlは以下のクラウドプロバイダーが提供するマネージドKubernetesのビルトイン認証を削除しました。
これらのプロバイダーは、クラウド固有の認証を提供するkubectlプラグインをリリースしています。
手順については以下のプロバイダーのドキュメントを参照してください:
(この変更とは関係なく、他の理由で同じエラーメッセージが表示される可能性もあります。)
オプションのkubectlの設定とプラグイン
シェルの自動補完を有効にする
kubectlはBash、Zsh、Fish、PowerShellの自動補完を提供しています。
これにより、入力を大幅に削減することができます。
以下にBash、Fish、Zshの自動補完の設定手順を示します。
はじめに
Bashにおけるkubectlの補完スクリプトはkubectl completion bash
コマンドで生成できます。
シェル内で補完スクリプトをsourceすることでkubectlの自動補完が有効になります。
ただし、補完スクリプトはbash-completionに依存しているため、事前にインストールしておく必要があります。
警告: bash-completionにはv1とv2の2つのバージョンがあります。
v1はBash 3.2(macOSのデフォルト)用で、v2はBash 4.1以降向けです。
kubectlの補完スクリプトはbash-completionのv1とBash 3.2では正しく
動作しません。
bash-completion v2と
Bash 4.1以降が必要になります。
したがって、macOSで正常にkubectlの補完を使用するには、Bash 4.1以降をインストールする必要があります(
手順)。
以下の手順では、Bash4.1以降(Bashのバージョンが4.1またはそれより新しいことを指します)を使用することを前提とします。
Bashのアップグレード
ここではBash 4.1以降の使用を前提としています。
Bashのバージョンは下記のコマンドで調べることができます:
バージョンが古い場合、Homebrewを使用してインストールもしくはアップグレードできます:
シェルをリロードし、希望するバージョンを使用していることを確認してください:
echo $BASH_VERSION $SHELL
Homebrewは通常、/usr/local/bin/bash
にインストールします。
bash-completionをインストールする
備考: 前述のとおり、この手順ではBash 4.1以降であることが前提のため、bash-completion v2をインストールすることになります(これとは逆に、Bash 3.2およびbash-completion v1の場合ではkubectlの補完は動作しません)。
type _init_completion
を実行することで、bash-completionがすでにインストールされていることを確認できます。
ない場合は、Homebrewを使用してインストールすることができます:
brew install bash-completion@2
このコマンドの出力で示されたように、~/.bash_profile
に以下を追記してください:
brew_etc="$(brew --prefix)/etc" && [[ -r "${brew_etc}/profile.d/bash_completion.sh" ]] && . "${brew_etc}/profile.d/bash_completion.sh"
シェルをリロードし、type _init_completion
を実行してbash-completion v2が正しくインストールされていることを検証してください。
kubectlの自動補完を有効にする
すべてのシェルセッションにてkubectlの補完スクリプトをsourceできるようにしなければなりません。
これを行うには複数の方法があります:
-
補完スクリプトを~/.bash_profile
内でsourceする:
echo 'source <(kubectl completion bash)' >>~/.bash_profile
-
補完スクリプトを/usr/local/etc/bash_completion.d
ディレクトリに追加する:
kubectl completion bash >/usr/local/etc/bash_completion.d/kubectl
-
kubectlにエイリアスを張っている場合は、エイリアスでも動作するようにシェルの補完を拡張することができます:
echo 'alias k=kubectl' >>~/.bash_profile
echo 'complete -o default -F __start_kubectl k' >>~/.bash_profile
-
kubectlをHomebrewでインストールした場合(前述の通り)、kubectlの補完スクリプトはすでに/usr/local/etc/bash_completion.d/kubectl
に格納されているでしょうか。
この場合、なにも操作する必要はありません。
備考: Homebrewでインストールしたbash-completion v2はBASH_COMPLETION_COMPAT_DIR
ディレクトリ内のすべてのファイルをsourceするため、後者の2つの方法が機能します。
どの場合でも、シェルをリロードしたあとに、kubectlの自動補完が機能するはずです。
備考: Fishに対する自動補完はkubectl 1.23以降が必要です。
Fishにおけるkubectlの補完スクリプトはkubectl completion fish
コマンドで生成できます。
シェル内で補完スクリプトをsourceすることでkubectlの自動補完が有効になります。
すべてのシェルセッションで使用するには、~/.config/fish/config.fish
に以下を追記してください:
kubectl completion fish | source
シェルをリロードしたあとに、kubectlの自動補完が機能するはずです。
Zshにおけるkubectlの補完スクリプトはkubectl completion zsh
コマンドで生成できます。
シェル内で補完スクリプトをsourceすることでkubectlの自動補完が有効になります。
すべてのシェルセッションで使用するには、~/.zshrc
に以下を追記してください:
source <(kubectl completion zsh)
kubectlにエイリアスを張っている場合でも、kubectlの自動補完は自動的に機能します。
シェルをリロードしたあとに、kubectlの自動補完が機能するはずです。
2: command not found: compdef
のようなエラーが出力された場合は、以下を~/.zshrc
の先頭に追記してください:
autoload -Uz compinit
compinit
kubectl convert
プラグインをインストールする
異なるAPIバージョン間でマニフェストを変換できる、Kubernetesコマンドラインツールkubectl
のプラグインです。
これは特に、新しいKubernetesのリリースで、非推奨ではないAPIバージョンにマニフェストを移行する場合に役に立ちます。
詳細については非推奨ではないAPIへの移行を参照してください。
-
次のコマンドを使用して最新リリースをダウンロードしてください:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert"
-
バイナリを検証してください(オプション)
kubectl-convertのチェックサムファイルをダウンロードします:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert.sha256"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert.sha256"
チェックサムファイルに対してkubectl-convertバイナリを検証します:
echo "$(cat kubectl-convert.sha256) kubectl-convert" | shasum -a 256 --check
正しければ、出力は次のようになります:
チェックに失敗すると、shasum
は0以外のステータスで終了し、次のような出力を表示します:
kubectl-convert: FAILED
shasum: WARNING: 1 computed checksum did NOT match
備考: 同じバージョンのバイナリとチェックサムをダウンロードしてください。
-
kubectl-convertバイナリを実行可能にしてください。
chmod +x ./kubectl-convert
-
kubectl-convertバイナリをPATH
の中に移動してください。
sudo mv ./kubectl-convert /usr/local/bin/kubectl-convert
sudo chown root: /usr/local/bin/kubectl-convert
備考: /usr/local/bin
がPATH環境変数の中に含まれるようにしてください。
-
インストールしたバージョンが最新であることを確認してください
何もエラーが表示されない場合は、プラグインが正常にインストールされたことを示しています。
-
プラグインのインストール後、インストールファイルを削除してください:
rm kubectl-convert kubectl-convert.sha256
macOS上のkubectlをアンインストールする
kubectl
のインストール方法に応じて、次の方法を使用してください。
コマンドラインを使用してkubectlをアンインストールする
-
システム上のkubectl
バイナリの場所を特定してください:
-
kubectl
バイナリを削除してください:
<path>
を前のステップのkubectl
バイナリのパスに置き換えてください。
例えばsudo rm /usr/local/bin/kubectl
。
Homebrewを使用してkubectlをアンインストールする
Homebrewを使用してkubectl
をインストールした場合は、次のコマンドを実行してください:
次の項目
3 - Windows上でのkubectlのインストールおよびセットアップ
始める前に
kubectlのバージョンは、クラスターのマイナーバージョンとの差分が1つ以内でなければなりません。
たとえば、クライアントがv1.30であれば、v1.29、v1.30、v1.31のコントロールプレーンと通信できます。
最新の互換性のあるバージョンのkubectlを使うことで、不測の事態を避けることができるでしょう。
Windowsへkubectlをインストールする
Windowsへkubectlをインストールするには、次の方法があります:
curlを使用してWindowsへkubectlのバイナリをインストールする
-
最新の1.30のパッチリリースをダウンロードしてください:
kubectl 1.30.0。
または、curl
がインストールされていれば、次のコマンドも使用できます:
curl.exe -LO "https://dl.k8s.io/release/v1.30.0/bin/windows/amd64/kubectl.exe"
-
バイナリを検証してください(オプション)
kubectl
のチェックサムファイルをダウンロードします:
curl.exe -LO "https://dl.k8s.io/v1.30.0/bin/windows/amd64/kubectl.exe.sha256"
チェックサムファイルに対してkubectl
バイナリを検証します:
-
kubectl
バイナリのフォルダーをPATH
環境変数に追加します。
-
kubectl
のバージョンがダウンロードしたものと同じであることを確認してください:
または、バージョンの詳細を表示するために次を使用します:
kubectl version --client --output=yaml
備考: Docker Desktop for Windowsは、それ自身のバージョンの
kubectl
を
PATH
に追加します。
Docker Desktopをすでにインストールしている場合、Docker Desktopインストーラーによって追加された
PATH
の前に追加するか、Docker Desktopの
kubectl
を削除してください。
-
Windowsへkubectlをインストールするために、ChocolateyパッケージマネージャーやScoopコマンドラインインストーラー、wingetパッケージマネージャーを使用することもできます。
choco install kubernetes-cli
winget install -e --id Kubernetes.kubectl
-
インストールしたバージョンが最新であることを確認してください:
-
ホームディレクトリへ移動してください:
# cmd.exeを使用している場合はcd %USERPROFILE%を実行してください。
cd ~
-
.kube
ディレクトリを作成してください:
-
作成した.kube
ディレクトリへ移動してください:
-
リモートのKubernetesクラスターを使うために、kubectlを設定してください:
New-Item config -type file
備考: Notepadなどの選択したテキストエディターから設定ファイルを編集してください。
kubectlの設定を検証する
kubectlがKubernetesクラスターを探索し接続するために、kubeconfigファイルが必要です。
これは、kube-up.shによりクラスターを作成した際や、Minikubeクラスターを正常にデプロイした際に自動生成されます。
デフォルトでは、kubectlの設定は~/.kube/config
に格納されています。
クラスターの状態を取得し、kubectlが適切に設定されていることを確認してください:
URLのレスポンスが表示されている場合は、kubectlはクラスターに接続するよう正しく設定されています。
以下のようなメッセージが表示されている場合は、kubectlは正しく設定されていないか、Kubernetesクラスターに接続できていません。
The connection to the server <server-name:port> was refused - did you specify the right host or port?
たとえば、ラップトップ上(ローカル環境)でKubernetesクラスターを起動するような場合、Minikubeなどのツールを最初にインストールしてから、上記のコマンドを再実行する必要があります。
kubectl cluster-info
がURLレスポンスを返したにもかかわらずクラスターにアクセスできない場合は、次のコマンドで設定が正しいことを確認してください:
kubectl cluster-info dump
エラーメッセージ'No Auth Provider Found'のトラブルシューティング
Kubernetes 1.26にて、kubectlは以下のクラウドプロバイダーが提供するマネージドKubernetesのビルトイン認証を削除しました。
これらのプロバイダーは、クラウド固有の認証を提供するkubectlプラグインをリリースしています。
手順については以下のプロバイダーのドキュメントを参照してください:
(この変更とは関係なく、他の理由で同じエラーメッセージが表示される可能性もあります。)
オプションのkubectlの設定とプラグイン
シェルの自動補完を有効にする
kubectlはBash、Zsh、Fish、PowerShellの自動補完を提供しています。
これにより、入力を大幅に削減することができます。
以下にPowerShellの自動補完の設定手順を示します。
PowerShellにおけるkubectlの補完スクリプトはkubectl completion powershell
コマンドで生成できます。
すべてのシェルセッションでこれを行うには、次の行を$PROFILE
ファイルに追加します。
kubectl completion powershell | Out-String | Invoke-Expression
このコマンドは、PowerShellを起動する度に自動補完のスクリプトを再生成します。
生成されたスクリプトを直接$PROFILE
ファイルに追加することもできます。
生成されたスクリプトを$PROFILE
ファイルに追加するためには、PowerShellのプロンプトで次の行を実行します:
kubectl completion powershell >> $PROFILE
シェルをリロードした後、kubectlの自動補完が機能します。
kubectl convert
プラグインをインストールする
異なるAPIバージョン間でマニフェストを変換できる、Kubernetesコマンドラインツールkubectl
のプラグインです。
これは特に、新しいKubernetesのリリースで、非推奨ではないAPIバージョンにマニフェストを移行する場合に役に立ちます。
詳細については非推奨ではないAPIへの移行を参照してください。
-
次のコマンドを使用して最新リリースをダウンロードしてください:
curl.exe -LO "https://dl.k8s.io/release/v1.30.0/bin/windows/amd64/kubectl-convert.exe"
-
バイナリを検証してください(オプション)。
kubectl-convert
のチェックサムファイルをダウンロードします:
curl.exe -LO "https://dl.k8s.io/v1.30.0/bin/windows/amd64/kubectl-convert.exe.sha256"
チェックサムファイルに対してkubectl-convert
バイナリを検証します:
-
kubectl-convert
バイナリのフォルダーをPATH
環境変数に追加します。
-
プラグインが正常にインストールされたことを確認してください。
何もエラーが表示されない場合は、プラグインが正常にインストールされたことを示しています。
-
プラグインのインストール後、インストールファイルを削除してください:
del kubectl-convert.exe
del kubectl-convert.exe.sha256
次の項目