Kubectl / Print Client And Server Version Current Context
Print Client And Server Version Current Context
Use kubectl version to display the client and server version information for your Kubernetes context.
$
Terminal kubectl version kubectl version #!/bin/bash
# Print Client And Server Version Current Context
kubectl version import subprocess
# Print Client And Server Version Current Context
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"kubectl",
"version"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: kubectl not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
To validate compatibility before applying updates or changes to the cluster environment.
Terminal Output
Expected runtime feedback
>
Output Client Version: v1.22.0
Server Version: v1.21.5
Kubernetes context: my-cluster Command Breakdown
What each part is doing
-
kubectl - Base Command
- The executable that performs this operation. Here it runs Kubectl before the shell applies any redirect operators.
How To Run
Execution path
- Step 1
Open your terminal.
- Step 2
Run the command: kubectl version.
- Step 3
Review the displayed client and server version information.
Alternative Approaches
Comparable commands in other tools
Alternative kubernetes tools for the same job.
Helm / Download Helm Chart Archive
helm get <chart_release_name> Minikube / Start Minikube In Background Mode minikube start --background Minikube / Start Minikube With Custom Addons minikube start --addons <metrics-server> Kubens / List Namespaces Kubens kubens Kubens / Switch Previous Namespace Kubens kubens -