I am trying to get the current Kubernetes version via the API, because depending on the version some things are not supported (e.g. readyz endpoint is not available before 1.16, so I want to check healthz endpoint instead).
I found the following endpoint: /version
Example result:
{
"major": "1",
"minor": "11+",
"gitVersion": "v1.11.0+d4cacc0",
"gitCommit": "d4cacc0",
"gitTreeState": "clean",
"buildDate": "2021-05-12T14:13:55Z",
"goVersion": "go1.10.8",
"compiler": "gc",
"platform": "linux/amd64"
}
Is this the correct approach to get the version via API? I thaught Kubernetes uses semantic versioning, why is the "+" in the minor String? Is this configurable? Where can I find a specification of this API/fields?
Ideally this should work for standalone and managed Kubernetes flavors (Openshift, GKE...).
GitVersion/gitVersionis the semantic versioning field.This is the version of the
kube-api-servercomponent specifically.The parsing is done by regex in The k8s.io/apimachinery package:
The
/versionendpoint is part of the documented API spec (operationId: "getCode") so should be pretty stable. It's whatkubectl versionuses so I doubt it will change easily.