Check Kubernetes Cluster Version [5 Methods]


Kubernetes Tutorial

Check Kubernetes Cluster Version - Overview

  • A Kubernetes Cluster consists of basically control plane and a set of worker nodes. We have a couple of components which are installed on the control plane and worker nodes to set up the Kubernetes Cluster completely. Some of these components are kubeadm, kubelet and kubectl. We can utilise these components to get the kubernetes cluster version.
  • Kubernetes versions are expressed as x.y.z, where x is the major version, y is the minor version, and z is the patch version
  • In highly-available (HA) clusters, the newest and oldest kube-apiserver instances must be within one minor version.
  • kubelet must not be newer than kube-apiserver, and may be up to two minor versions older.
  • kube-controller-manager, kube-scheduler, and cloud-controller-manager must not be newer than the kube-apiserver instances they communicate with. They are expected to match the kube-apiserver minor version, but may be up to one minor version older (to allow live upgrades).
  • kubectl is supported within one minor version (older or newer) of kube-apiserver.

 

In this tutorial I will share multiple methods and commands to check Kubernetes Cluster Version in a Kubernetes Cluster.

 

Method-1: Check Kubernetes Cluster version using kubectl

The simplest way to check kubernetes cluster version would be using kubectl command. You can execute kubectl version to display long list of detail information related to Kubernetes Cluster (Both Server and Client):

 ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:38:50Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:32:41Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}

We can trim the output only to get the Server and Client version using:

 ~]# kubectl version --short=true
Client Version: v1.22.2
Server Version: v1.22.2

In case you only need the client version then you can execute:

~]# kubectl version --short --client=true
Client Version: v1.22.2

~]# kubectl version --short --client=true
Client Version: v1.18.8

You can also get the output in JSON format using kubectl version -o json command as shown below:
Check Kubernetes Cluster Version [5 Methods]

 

Method-2: Check Kubernetes Cluster version using kubeadm

We can use kubeadm upgrade plan command to check the Kubernetes Cluster version. Now this may not be the best command when you plan to check the cluster version in an automated way but it does gives you quiet detailed information of your existing cluster version:

For example, here I have executed kubeadm upgrade plan on a Cluster:

NOTE:
This command will NOT upgrade your cluster. Instead it will just give you a detailed information on the installed version of different Kubernetes components along with version details of available respective components. So you can safely execute this command.
controlplane $ kubeadm upgrade plan
[upgrade/config] Making sure the configuration is correct:
[upgrade/config] Reading configuration from the cluster...
[upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[preflight] Running pre-flight checks.
[upgrade] Running cluster health checks
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.21.0
[upgrade/versions] kubeadm version: v1.21.0
I0918 13:26:14.435638   53101 version.go:254] remote version is much newer: v1.22.2; falling back to: stable-1.21
[upgrade/versions] Target version: v1.21.5
[upgrade/versions] Latest version in the v1.21 series: v1.21.5

Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT   CURRENT       TARGET
kubelet     2 x v1.21.0   v1.21.5

Upgrade to the latest version in the v1.21 series:

COMPONENT                 CURRENT    TARGET
kube-apiserver            v1.21.0    v1.21.5
kube-controller-manager   v1.21.0    v1.21.5
kube-scheduler            v1.21.0    v1.21.5
kube-proxy                v1.21.0    v1.21.5
CoreDNS                   v1.8.0     v1.8.0
etcd                      3.4.13-0   3.4.13-0

You can now apply the upgrade by executing the following command:

        kubeadm upgrade apply v1.21.5

Note: Before you can perform this upgrade, you have to update kubeadm to v1.21.5.

_____________________________________________________________________


The table below shows the current state of component configs as understood by this version of kubeadm.
Configs that have a "yes" mark in the "MANUAL UPGRADE REQUIRED" column require manual config upgrade or
resetting to kubeadm defaults before a successful upgrade can be performed. The version to manually
upgrade to is denoted in the "PREFERRED VERSION" column.

API GROUP                 CURRENT VERSION   PREFERRED VERSION   MANUAL UPGRADE REQUIRED
kubeproxy.config.k8s.io   v1alpha1          v1alpha1            no
kubelet.config.k8s.io     v1beta1           v1beta1             no
_____________________________________________________________________

As you can see, it gives you a detailed list of information of all the different component version used in your Kubernetes Cluster.

On this cluster, kubectl shows following cluster version:

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

On a different cluster which was already running on the latest available version:

[root@centos8-1 ~]# kubeadm upgrade plan
[upgrade/config] Making sure the configuration is correct:
[upgrade/config] Reading configuration from the cluster...
[upgrade/config] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[preflight] Running pre-flight checks.
[upgrade] Running cluster health checks
[upgrade] Fetching available versions to upgrade to
[upgrade/versions] Cluster version: v1.22.2
[upgrade/versions] kubeadm version: v1.22.2
[upgrade/versions] Target version: v1.22.2
[upgrade/versions] Latest version in the v1.22 series: v1.22.2

As you can see here, since the cluster was already on the latest available version we were not given any upgrade plan and the output was much shorted compared to previous cluster.

On this cluster, the kubectl version is as follows:

~]# kubectl version --short
Client Version: v1.22.2
Server Version: v1.22.2

 

Method-3: Check Kubernetes Cluster version using kubectl get nodes command

We can check the Kubernetes Cluster Nodes version using kubectl get nodes command which will list all the available worker nodes along with the kubectl version on those nodes:

For example on this Kubernetes Cluster, my worker nodes and control plane are on 1.21.0 version:

controlplane $ kubectl get nodes
NAME           STATUS   ROLES                  AGE    VERSION
controlplane   Ready    control-plane,master   103m   v1.21.0
node01         Ready    <none>                 103m   v1.21.0

For example on this Kubernetes Cluster, my worker nodes and control plane are on 1.18.8 version:

~]# kubectl get nodes
NAME                             STATUS   ROLES    AGE    VERSION
ncs20fp1-02-w8-ipv4-control-01   Ready    <none>   182d   v1.18.8
ncs20fp1-02-w8-ipv4-control-02   Ready    <none>   182d   v1.18.8
ncs20fp1-02-w8-ipv4-control-03   Ready    <none>   182d   v1.18.8
ncs20fp1-02-w8-ipv4-edge-01      Ready    <none>   182d   v1.18.8
ncs20fp1-02-w8-ipv4-edge-02      Ready    <none>   182d   v1.18.8
ncs20fp1-02-w8-ipv4-worker-01    Ready    <none>   182d   v1.18.8

Similarly on this Kubernetes Cluster, my control plane and worker nodes are on 1.22.2 version:

~]# kubectl get nodes
NAME                    STATUS   ROLES                  AGE     VERSION
centos8-1.example.com   Ready    control-plane,master   6h25m   v1.22.2
centos8-2.example.com   Ready    <none>                 6h12m   v1.22.2
centos8-3.example.com   Ready    <none>                 6h12m   v1.22.2

 

Method-4: Check Kubernetes Cluster version using kubectl proxy command

We can get detailed information about any Kubernetes Cluster using kubectl proxy command. This command will basically create a proxy server which you can also refer as an application level gateway between the localhost (i.e. control plane) and the Kubernetes API Server. Next we can query the API server to get complete detail about the respective Kubernetes Cluster which will also display the cluster version:

From one terminal, execute the following command:

~]# kubectl proxy
Starting to serve on 127.0.0.1:8001

Now from another terminal execute curl http://localhost:8001/version -k as shown below:
Check Kubernetes Cluster Version [5 Methods]

Here you can get the Major and Minor version of your Kubernetes Cluster.

 

Method 5: Check Kubernetes Cluster version using kubelet command

The kubelet is the primary node agent that runs on each node. We can also check the version of kubelet on the control plane node to determine the Kubernetes Cluster version.

For example, here I have provide the kubelet version output from different clusters:

controlplane $ kubelet --version
Kubernetes v1.20.0

controlplane $ kubelet --version
Kubernetes v1.21.0

 ~]# kubelet --version
Kubernetes v1.22.2

 

Summary

In this tutorial we covered different methods which can be used to check Kubernetes Cluster version. You can use these methods to automate your scripts or jobs. I can understand if you get confused wondering that there are so many components inside the cluster so which method would be the best reliable way. In my option you can use the kubectl command from Method 1 which gives you short and crisp information. You may also use kubeadm upgrade plan which gives you a very detailed information about your cluster and the installed component version.

Lastly I hope the steps from the article to check Kubernetes Cluster version was helpful. So, let me know your suggestions and feedback using the comment section.

 

References

Kubernetes Version Skew Policy

 

Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment