<p>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).</p>
<p>I found the following endpoint: <code>/version</code></p>
<p>Example result:</p>
<pre><code>{
  &quot;major&quot;: &quot;1&quot;,
  &quot;minor&quot;: &quot;11+&quot;,
  &quot;gitVersion&quot;: &quot;v1.11.0+d4cacc0&quot;,
  &quot;gitCommit&quot;: &quot;d4cacc0&quot;,
  &quot;gitTreeState&quot;: &quot;clean&quot;,
  &quot;buildDate&quot;: &quot;2021-05-12T14:13:55Z&quot;,
  &quot;goVersion&quot;: &quot;go1.10.8&quot;,
  &quot;compiler&quot;: &quot;gc&quot;,
  &quot;platform&quot;: &quot;linux/amd64&quot;
}
</code></pre>
<p>Is this the correct approach to get the version via API? I thaught Kubernetes uses semantic versioning, why is the &quot;+&quot; in the minor String? Is this configurable?
Where can I find a specification of this API/fields?</p>
<p>Ideally this should work for standalone and managed Kubernetes flavors (Openshift, GKE...).</p>

<p><code>GitVersion</code>/<code>gitVersion</code> is the semantic versioning field.</p>
<p>This is the version of the <code>kube-api-server</code> component specifically.</p>
<p>The parsing is done by <a href="https://github.com/kubernetes/apimachinery/blob/57f2a0733447cfd41294477d833cce6580faaca3/pkg/util/version/version.go#L35-L40" rel="nofollow noreferrer">regex</a> in The <a href="https://github.com/kubernetes/apimachinery" rel="nofollow noreferrer">k8s.io/apimachinery</a> package:</p>
<pre><code>^\s*v?([0-9]+(?:\.[0-9]+)*)(.*)*$`
</code></pre>
<p>The <code>/version</code> endpoint is part of the documented API spec (<code>operationId: &quot;getCode&quot;</code>) so should be pretty stable. It's what <code>kubectl version</code> uses so I doubt it will change easily.</p>
