jupyterhub / zero-to-jupyterhub-k8s

Helm Chart & Documentation for deploying JupyterHub on Kubernetes
https://zero-to-jupyterhub.readthedocs.io
Other
1.52k stars 791 forks source link

Question on how to run code on startup of a user pod's container #1705

Closed chrisroat closed 4 years ago

chrisroat commented 4 years ago

I have jupyterhub running on K8s, which has a service account json key file loaded from a K8s secret. The env var GOOGLE_APPLICATION_CREDENTIALS is set to point to the file.

I find that in order for gsutil to work properly (via subprocess.run), I have to execute the following command:

gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}

What is the proper config/hook to setup in order that this is done automatically for a singleuser?

Thanks!

welcome[bot] commented 4 years ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

consideRatio commented 4 years ago

Hi @chrisroat,

I'm not sure what makes the most sense or what would work well, but I'd try the postStart lifecycleHook first.

support[bot] commented 4 years ago

Hi there @chrisroat :wave:!

I closed this issue because it was labelled as a support question.

Please help us organize discussion by posting this on the http://discourse.jupyter.org/ forum.

Our goal is to sustain a positive experience for both users and developers. We use GitHub issues for specific discussions related to changing a repository's content, and let the forum be where we can more generally help and inspire each other.

Thanks you for being an active member of our community! :heart:

meeseeksmachine commented 4 years ago

This issue has been mentioned on Jupyter Community Forum. There might be relevant details there:

https://discourse.jupyter.org/t/gcloud-service-account-activation-on-zero-to-jupyterhub/4816/2

chrisroat commented 4 years ago

@consideRatio Thanks for the tip. For the record, in order to pick up the environmental var, I needed

  lifecycleHooks:
    postStart:
      exec:
        command:
          - 'sh'
          - '-c'
          - "gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}"