Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Kubernetes cluster name from K8s API

As stated in the title, is it possible to find out a K8s cluster name from the API? I looked around the API and could not find it.

like image 678
Alex Avatar asked Jul 07 '16 09:07

Alex


People also ask

How can I get cluster ID in Kubernetes?

To find out the Kubernetes cluster ID or NAME , get a list of Kubernetes clusters from the folder or detailed information about the Kubernetes cluster.

How do I find my Kubernetes API URL?

From inside the pod, kubernetes api server can be accessible directly on "https://kubernetes.default". By default it uses the "default service account" for accessing the api server. So, we also need to pass a "ca cert" and "default service account token" to authenticate with the api server.


2 Answers

kubectl config current-context does the trick (it outputs little bit more, like project name, region, etc., but it should give you the answer you need).

like image 121
usamec Avatar answered Sep 22 '22 07:09

usamec


Unfortunately a cluster doesn't know its own name, or anything else that would uniquely identify it (K8s issue #44954). I wanted to know for helm issue #2055.

like image 40
tback Avatar answered Sep 22 '22 07:09

tback