Get current user name in pod yaml file

939 views
Skip to first unread message

lppier

unread,
Nov 9, 2017, 8:54:45 PM11/9/17
to Kubernetes user discussion and Q&A
In my pod yaml file, I need to mount the user's current directory for use within the container. 

- hostPath:
    path
: /nfs/data1/home/cys


where cys is the user. 
How can I grab the current linux user in the pod spec? I can't seem to find any info on this. 
I've tried
/nfs/data1/home/$USER

and
/nfs/data1/home/[$USER]


they don't seem to work. 

Thanks. 

Rodrigo Campos

unread,
Nov 9, 2017, 9:55:58 PM11/9/17
to kubernet...@googlegroups.com
On Thursday, November 9, 2017, lppier <mads...@gmail.com> wrote:
In my pod yaml file, I need to mount the user's current directory for use within the container. 

- hostPath:
    path
: /nfs/data1/home/cys


where cys is the user. 
How can I grab the current linux user in the pod spec? I can't seem to find any info on this. 

What do you mean with "current user"? The user running the pod? That can be specified in the yaml statically. I can't think of anything dynamic, so not sure what you mean :-/

lppier

unread,
Nov 9, 2017, 10:26:59 PM11/9/17
to Kubernetes user discussion and Q&A
Yes, I meant dynamically, like I would $USER in linux. Is it possible? 

Rodrigo Campos

unread,
Nov 9, 2017, 11:16:29 PM11/9/17
to kubernet...@googlegroups.com
Not sure what you mean, probably the answer is "no". But I  don't understand what you want.

Do you want to replace $USER with what, exactly? The user running what?

What are you trying to do?

It seems like you are mixing things that do not have anything to do with each other. But, I might be wrong, can you please elaborate?

--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.

Tim Hockin

unread,
Nov 10, 2017, 12:25:48 AM11/10/17
to Kubernetes user discussion and Q&A
I don't think that is exposed anywhere, but might be a reasonable extension to downward API.  Patches and proposals welcome.

Rodrigo Campos

unread,
Nov 10, 2017, 9:25:42 AM11/10/17
to lppier, kubernet...@googlegroups.com
Oh, sorry, Kubernetes users was removed. Adding it back

On Friday, November 10, 2017, Rodrigo Campos <rodr...@gmail.com> wrote:
So they will create the deployment and you want that user executing that?

Then i think this will work: just a template and modify those variables in the fly, and then send the modified yaml.

There are some tools for that, but if the case is so simple I'd use just a shell script (with sed or awk).

Does that solve it?

On Friday, November 10, 2017, lppier <mads...@gmail.com> wrote:
Say I am the linux user with the name "pier" 
The volume mount in my pod fileis : 

hostPath:
  path
: /nfs/data1/home/pier


As I have multiple users, I don't want user mounting /nfs/data1/home/pier all the time, but rather

/nfs/data1/home/<their_user_name>

Of course, it would not be too difficult to ask them to edit the pod yaml themselves. Just wondering whether I can do it for them by using their linux username in the pod file. 

Rodrigo Campos

unread,
Nov 11, 2017, 8:55:24 AM11/11/17
to lppier, kubernet...@googlegroups.com
No problem! Hope it works :)

On Saturday, November 11, 2017, lppier <mads...@gmail.com> wrote:
Yup I can do that. Was just wondering .. thanks for your help! 
Reply all
Reply to author
Forward
0 new messages