0

Assume I am running a Javascript server in a Pod in Kubernetes. How can I get the name of that pod or its ID?

Similarly, if I am running a Python server in namespace A, how can I get the names resp. other IDs of all pods in namespace B?

tobias
  • 501
  • 1
  • 6
  • 15
  • Please read: [Can I ask only one question per post?](https://meta.stackexchange.com/questions/222735/can-i-ask-only-one-question-per-post) --- For question 1, there are way to pass the pod's name as environment variable into the pod. For question 2, we'd most probably need to interact with the kubernetes API. – Turing85 Oct 28 '22 at 21:03

1 Answers1

0

You can get the name of the pod as seen inside the Kubernetes Cluster by checking the HOSTNAME variable inside the pod.

Ref: https://kubernetes.io/docs/concepts/containers/container-environment/

For your second question, you can always run kubectl inside a container running in the cluster. Check this question: Run kubectl inside a cluster

HiroCereal
  • 550
  • 1
  • 11