Reputation: 495
How can an application running in a pod on Kubernetes cluster find the currently running number of pods of the same image (instances of the same image)? Is there also a way to uniquely identify each pod in a collection of pods of the same type?
For Eg. If I have 3 pods of the same image running in my Kubernetes Cluster, I want my application running in the pods to know there are 3 instances running at the moment and possibly be able to identify them as 0 or 1 or 2 in the collection of 3 pods based on may be start time.
Upvotes: 1
Views: 1483
Reputation: 186
In order to do that you can debug kubectl command. Kubectl takes a parameter -v9. You can get the endpoints of kubectl execution by making requests.
In the deployment output you can get desired state of pods running on your system. With -v9 you can get the endpoints of api server used by kubectl deployment command
Another option is searching on CoreDns and skydns. These always retrieve service list and pods by querying api server. You should take a look the source code of them.
Upvotes: 0
Reputation: 8825
If your application needs to know that information, you will need the following:
Upvotes: 2