kubernetes / kubernetes/kubectl

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

Open
#1,216 19 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug lifecycle/rotten needs-triage
Dominant language
Go
Stars
3.3k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

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 --client                               
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
$ 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the kubectl version commands shown in the issue with no context and with an offline current context. Trace the kubectl version command entry point and compare its client-only, default, and remote-version behavior. Done means local version checks show the client and Kustomize versions without warnings or unnecessary server-connection errors, while an explicit remote check still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.