Ora

How to check K8s version?

Published in Kubernetes Versioning 3 mins read

You can check your Kubernetes (K8s) client and server versions by running the kubectl version command in your terminal. This essential command provides details about both your local kubectl tool and the remote Kubernetes cluster it interacts with.

The kubectl command-line tool serves as your primary interface for managing and interacting with a Kubernetes cluster. To determine the version of your local kubectl client and the version of the Kubernetes cluster it's connected to, use the kubectl version command. This information is critical for ensuring compatibility and troubleshooting potential issues.

Understanding Kubernetes Version Components

A Kubernetes environment fundamentally comprises two main version components:

  1. Client Version: This refers to the version of the kubectl executable installed on your local machine.
  2. Server Version: This indicates the version of the Kubernetes cluster's control plane, specifically the kube-apiserver component.

Knowing both versions is crucial for maintaining a healthy and functional environment. Generally, kubectl clients are designed to be compatible with Kubernetes server versions that are one minor version older or newer (e.g., kubectl 1.28 will typically work well with Kubernetes 1.27, 1.28, and 1.29 clusters).

Step-by-Step Guide to Check K8s Version

Follow these straightforward steps to retrieve your Kubernetes version information:

  1. Open your terminal or command prompt on your local system.
  2. Type the command kubectl version
  3. Press Enter.

The output will display detailed version information for both your kubectl client and the Kubernetes cluster it is currently configured to communicate with.

Example Output:

Client Version: v1.28.3
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.7-gke.1126000

In the example above, the kubectl client is version 1.28.3, while the Kubernetes cluster (server) is running version 1.27.7 (with a specific build reference for Google Kubernetes Engine).

Key Details from the Output

The kubectl version command provides several pieces of vital information:

  • Client Version: Shows the Major, Minor, and Patch version of your local kubectl binary.
  • Kustomize Version: Displays the version of Kustomize, a tool for customizing Kubernetes configurations, which is often bundled with kubectl.
  • Server Version: Indicates the Major, Minor, and Patch version of the Kubernetes API server running on your cluster. This is the definitive version of your Kubernetes cluster.

Practical Insights and Troubleshooting

  • kubectl Not Found Error: If you encounter an error message such as "command not found," it means kubectl is either not installed on your system or its executable path is not included in your system's PATH environment variable. You can find detailed instructions on how to set it up in the official Kubernetes documentation for kubectl installation.
  • Server Version Unavailable: If the output only shows the Client Version and an error for the Server Version (e.g., "Unable to connect to the server: dial tcp..."), it indicates that your kubectl client is not configured to connect to a Kubernetes cluster, or the cluster itself is currently unreachable. In such cases, verify your kubeconfig file settings and network connectivity to the cluster.
  • Version Compatibility: To ensure optimal functionality and prevent unexpected issues, it's recommended to keep your kubectl client and Kubernetes cluster server versions within one minor version difference. For comprehensive compatibility guidelines, refer to the Kubernetes version skew policy.

Understanding your Kubernetes version is a fundamental practice for effective deployment management, configuration application, and efficient diagnosis of any cluster-related issues.