106

Let say I want to find the kubelet and apiserver version of my k8s master(s), what's the best way to do it?

I am aware of the following commands:

kubectl cluster-info

which only shows the endpoints.

kubectl get nodes; kubectl describe node <node>;

which shows very detail information but only the nodes and not master.

There's also

kubectl version

but that only shows the kubectl version and not the kubelet or apiserver version.

What other commands can I use to identify the properties of my cluster?

Kenny Ho
  • 3,247
  • 5
  • 19
  • 24
  • 1
    Found another one called `kubectl get cs/componentstatuses`, which lists controller-manager and scheduler but it does not show version and `kubectl describe cs` is not implemented. – Kenny Ho Jul 06 '16 at 17:59

3 Answers3

132

kubectl version also shows the apiserver version. For example, this is the output when I run it:

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.4", GitCommit:"3eed1e3be6848b877ff80a93da3785d9034d0a4f", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.4", GitCommit:"3eed1e3be6848b877ff80a93da3785d9034d0a4f", GitTreeState:"clean"}

The second line ("Server Version") contains the apiserver version. There isn't a way to get the master's kubelet version if it isn't registered as one of the nodes (which it isn't if it isn't showing up in kubectl get nodes), but in most deployments it'll be the same version as the apiserver.

Alex Robinson
  • 12,633
  • 2
  • 38
  • 55
  • 15
    You can also add `-o yaml` to most commands to get more details, e.g. `kubectl get nodes -o yaml` will give you the nodes' kubelet versions. – konradstrack Jul 06 '16 at 18:03
41

kubectl version --short will give you a short and sweet version of your k8-cluster

aathith@k8-master:~# kubectl version --short
Client Version: v1.18.1
Server Version: v1.18.1

edit 1:
In terminal 1

aathith@k8-master:~# kubectl proxy
Starting to serve on 127.0.0.1:8001

In terminal 2

aathith@k8-master:~# curl http://localhost:8001/version -k
{
  "major": "1",
  "minor": "18",
  "gitVersion": "v1.18.1",
  "gitCommit": "e0fccafd69541e3750d460ba0f9743b90336f24f",
  "gitTreeState": "clean",
  "buildDate": "2020-04-16T11:35:47Z",
  "goVersion": "go1.13.9",
  "compiler": "gc",
  "platform": "linux/amd64"
}

AATHITH RAJENDRAN
  • 4,689
  • 8
  • 34
  • 58
-1

yes i agree with above answers that most of the time kubectl version --short will be the same as kubelet's and apiserver version.

But according to k8s documentation : kubectl is supported within one minor version (older or newer) of kube-apiserver so there is a possibility that kubectl version can be different.

[Kubenetes doc screenshot] : https://i.stack.imgur.com/QSnlC.png

If you are able to see the nodes using kubectl get nodes then best way to get kubelet version by performing below commands

kubectl get nodes -o yaml | grep -i 'kubelet'
kubectl get nodes -o yaml | grep -i 'apiserver'

kubectl get nodes -o yaml | grep -i 'apiserver' output screenshot

kubectl get nodes -o yaml | grep -i 'kubelet' output screenshot

you can remove grep and search for other attributes also in yaml

  • `kubectl version` will return a `Server version` along with the `Client version`. This `Server version` *is* the kube-api server version. Although your solution of getting and grepping nodes does work, `kubectl version` (with or without the `--short` flag) will give an accurate kube-api server version, and is much lighter and easier to read than getting and grepping all the nodes like your solution. – Tijmen Nov 16 '22 at 13:10