My service X is running in a pod P with Namespace N. how do I find out namespace info from withing Service X using Kubernetes go client API?
I'm not sure what is meant by go client API
. The pod's namespace is in /var/run/secrets/kubernetes.io/serviceaccount/namespace
so this "service X" just needs to read this file.
Alternatively, you can also use the Downward API.
I figured i can pass on pod, namespace and more using Environment variables while creating a new pod using go-client. The way to do it is by specifying environment variable key/val pair in PodSpec as below:
Env: []v1.EnvVar{
{Name: "POD_NAME", Value: podname},
{Name: "POD_NAMESPACE", Value: nsname},
},
then from within a pod, i can read this env. variables using os package.