kubectl: Finding local kubectl version either requires timeout or deprecated option (?)

What happened:

  • I wanted to find out the version of kubectl I have installed, even though I have no selected context.
  • I wanted to find out the version of kubectl I have installed, even though I have a current context that is offline.

Sample console sessions:

laptop:~$ kubectl version --short
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.24.0
Kustomize Version: v4.5.4
Unable to connect to the server: dial tcp 203.0.113.42:443: connect: no route to host
$ kubectl version --short
Flag --short has been deprecated, and will be removed in the future. The --short output will become the default.
Client Version: v1.24.0
Kustomize Version: v4.5.4
The connection to the server localhost:8080 was refused - did you specify the right host or port?
$ kubectl version 
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.0", GitCommit:"4ce5a8954017644c5420bae81d72b09b735c21f0", GitTreeState:"clean", BuildDate:"2022-05-03T13:46:05Z", GoVersion:"go1.18.1", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.4
The connection to the server localhost:8080 was refused - did you specify the right host or port?

What you expected to happen: Something like:

  • kubectl version shows the client version only.
  • kubectl version --client does not show any warning.

For example:

$ kubectl version
Client Version: v1.24.0
Kustomize Version: v4.5.4
$ kubectl version --client
Client Version: v1.24.0
Kustomize Version: v4.5.4

It’s OK to have kubectl version --include-cluster-info or kubectl version --remote show the remote version too.

I would also be OK if kubectl version only checked the remote version when a current context is explicitly set (no fallback to an implicit server URL).

How to reproduce it (as minimally and precisely as possible):

  1. Visit https://kubernetes.io/docs/tasks/tools/#kubectl
  2. Install kubectl as instructed and, on a vanilla system, check the kubectl version.

Anything else we need to know?: As a project, we need a way for people who are setting up a brand new kubectl to confirm that they have a working and current kubectl.

It’s very helpful if this confirmation step doesn’t require explaining that there is a warning: it’s good practice not to have people become accustomed to seeing and then skipping warning messages.

Environment:

  • Kubernetes client and server versions (use kubectl version): v1.24.0
  • Cloud provider or hardware configuration: n/a
  • OS (e.g: cat /etc/os-release): Linux, but relevant to all OSs

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 17 (13 by maintainers)

Most upvoted comments

Actually, we could mention that both

  • kubectl version --client -ojson | jq -r .clientVersion.gitVersion
  • kubectl version -oyaml --client|awk '/gitVersion/{print $2;}'

are viable options, and let users choose.