Reputation: 41
Like to know if there is a way to identify Master IP address (API server Host & port) from the application that I run in POD?. ( say I create a kubernetes cluster A, with Master public IP address x.x.x.x; and I create a pod with my app (say a golang or J2ee) on a kubernetes minion belonging to that cluster A. From the App process that is running on cluster A minion , we like to know the public IP address of that Master (x.x.x.x) )
I do not find any Environmental variables for the same.
Can any one help?.
Upvotes: 0
Views: 2840
Reputation: 14053
The api service is exposed via a k8s service. You would need to use the API to access the service config. You can get access to the API through the service endpoint (the address is in an env variable) but you'll have to have the necessary creds to do anything useful. They're in a subdirectory of /var/run/secrets/kubernetes.io
depending on which service account your pod is running under. You can either access the endpoint directly, over https or you can run a proxy in your pod. See http://kubernetes.io/docs/user-guide/accessing-the-cluster/#accessing-the-api-from-a-pod.
An example of using curl
to hit the API server is given in https://stackoverflow.com/a/30739416/191215.
The api endpoint you want is /api/v1/endpoints
. Look for the item
with a metadata.name
of kubernetes
. The external endpoint should be one of the subsets
addresses
.
I believe this is true for all k8s implementations but have only tested it on GKE and from docker-machine
.
Upvotes: 2
Reputation: 13377
The DNS name kubernetes
should resolve to a virtual IP address that will route to the master so that you can hit the apiserver.
Upvotes: 0