↓メインコンテンツへスキップ
  1. Blogs/

kubectl versionでクライアントとサーバーのバージョンを確認する

2 分
Kubernetes
0222-nnn
著者
0222-nnn
猫が好き
目次

kubectl versionでクライアントとサーバーのバージョンを確認する
#

概要
#

kubectl versionは、クライアントとAPIサーバーのバージョンを確認するコマンドです。以下は2022年にKubernetes v1.23.9で確認した出力例です。現在のkubectlでは表示形式や利用できるオプションが異なる場合があります。

クライアントとサーバーのマイナーバージョンが異なる場合は、バージョンスキューポリシーでサポート範囲を確認します。

コマンド
#

kubectl version

オプション
#

当時のkubectl version --helpには、クライアントだけの表示や出力形式を選ぶオプションが記載されていました。

$ kubectl version --help
Print the client and server version information for the current context.

Examples:
  # Print the client and server versions for the current context
  kubectl version

Options:
      --client=false: If true, shows client version only (no server required).
  -o, --output='': One of 'yaml' or 'json'.
      --short=false: If true, print just the version number.

Usage:
  kubectl version [flags] [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
$

コマンド 実行結果
#

以下からはコマンドを実行したらどうなるのかを見ていきます。

kubectl version
#

オプションなしでは、クライアントとサーバーのバージョン、ビルド日時などが表示されました。

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.9", GitCommit:"c1de2d70269039fe55efb98e737d9a29f9155246", GitTreeState:"clean", BuildDate:"2022-07-13T14:26:51Z", GoVersion:"go1.17.11", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.9", GitCommit:"c1de2d70269039fe55efb98e737d9a29f9155246", GitTreeState:"clean", BuildDate:"2022-07-13T14:19:57Z", GoVersion:"go1.17.11", Compiler:"gc", Platform:"linux/amd64"}
$

kubectl version –client
#

クライアントだけに絞った情報を表示するオプションです。

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.9", GitCommit:"c1de2d70269039fe55efb98e737d9a29f9155246", GitTreeState:"clean", BuildDate:"2022-07-13T14:26:51Z", GoVersion:"go1.17.11", Compiler:"gc", Platform:"linux/amd64"}
$

kubectl version –short
#

v1.23.9では、クライアントとサーバーのバージョン番号だけを表示できました。現行のkubectlには--shortを使えない版があるため、以下は当時の実行例です。現在のオプションは公式リファレンスで確認してください。

$ kubectl version --short
Client Version: v1.23.9
Server Version: v1.23.9
$

その他
#

各NodeのKubernetesバージョン、OS、コンテナランタイムなどは、kubectl get nodes -o wideで確認できます。

$ kubectl get nodes -o wide
NAME         STATUS     ROLES                  AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION       CONTAINER-RUNTIME
kubemaster   Ready      control-plane,master   23d   v1.23.9   192.168.56.2   <none>        Ubuntu 18.04.6 LTS   4.15.0-191-generic   docker://19.3.11
kubenode01   NotReady   <none>                 23d   v1.23.9   192.168.56.3   <none>        Ubuntu 18.04.6 LTS   4.15.0-191-generic   docker://19.3.11
kubenode02   Ready      <none>                 23d   v1.23.9   192.168.56.4   <none>        Ubuntu 18.04.6 LTS   4.15.0-191-generic   docker://19.3.11
$

参考情報
#