Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can a pod discover its namespace? #9474

Closed
justinsb opened this issue Jun 9, 2015 · 4 comments
Closed

Can a pod discover its namespace? #9474

justinsb opened this issue Jun 9, 2015 · 4 comments
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@justinsb
Copy link
Member

justinsb commented Jun 9, 2015

In #9473 I asked if there was an easy way to discover resource limits without querying the API. But maybe I should just be querying the API... It seems easy, except that I don't know how to find my namespace.

I think I can do this:

POD_NAME=`cat /etc/hostname`
NAMESPACE=default # ???
curl http://${KUBERNETES_RO_SERVICE_HOST}:${KUBERNETES_RO_SERVICE_PORT}/api/v1beta3/namespaces/${NAMESPACE}/pods/${POD_NAME}

And then I get everything (labels, resources etc), which is great.

But:

  1. How can I discover my namespace?
  2. Will this continue to be supported? I can imagine that we don't want to give access to the entire cluster state to pods, but hopefully at least same-namespace or self-identity will be allowed.
  3. Is it safe to assume that hostname == pod-name (and if not, is there a way to discover my pod-name)?
@brendandburns brendandburns modified the milestone: v1.0-candidate Jun 9, 2015
@dchen1107
Copy link
Member

I filed #9433 yesterday related to pod and namespace and more discussion can be found at: #9356 (comment)

@goltermann goltermann added the kind/support Categorizes issue or PR as a support question. label Jun 9, 2015
@goltermann goltermann modified the milestones: v1.0-post, v1.0-candidate Jun 9, 2015
@justinsb
Copy link
Member Author

@dchen1107: thanks for that link, although I don't know that it applies here. To be clear - I'm inside a container, and I would like to get the pod info that applies to me from the API. I don't know how to get my namespace, nor am I certain that my hostname was always my name.

I did figure out that I could look at my IP, which is my podIP in the API. Sadly I don't think I'm allowed to use that as a fieldSelector ("message": "field label not supported: podIP"), but then I can at least use that to unambiguously figure out which pod I am. It's not great, but it does work!

@derekwaynecarr
Copy link
Member

@justinsb - you can get the namespace information from the downward API.

see the example here:

https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/downward_api.md

Closing the issue, re-open if this did not address your concern.

@justinsb
Copy link
Member Author

Thanks @derekwaynecarr - that is a good option that I wasn't aware of!

I was hoping for something that didn't require the manifest writer to do anything, but maybe that's over-optimizing. (I'm thinking about packaged k8s apps that can just be deployed and will self-configure, but it'll probably involve a service & and an rc anyway so this would actually work great).

Between this and the option of querying the k8s API I have some reasonable options!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

5 participants