jupyterhub / zero-to-jupyterhub-k8s

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

Jupyterhub K8s - Issue with Changing User from Jovyan to NB_USER #1411

Closed mgotham900 closed 4 years ago

mgotham900 commented 4 years ago

Everything works well until we wanted to set the NB_USER to the logged in user. When changed the config to run as root and start.sh as default cmd, getting the below error in the log and the container is failing to start. Any help is highly appreciated. @yuvipanda @ryanlovett

Set username to: user1 Relocating home dir to /home/user1 mv: cannot move '/home/jovyan' to '/home/user1': Device or resource busy

Here is the config.yaml

singleuser:
  defaultUrl: "/lab"
  uid: 0
  fsGid: 0
hub:
  extraConfig: |
    c.KubeSpawner.args = ['--allow-root']
    c.Spawner.cmd = ['start.sh','jupyterhub-singleuser']
    def notebook_dir_hook(spawner):
        spawner.environment = {'NB_USER':spawner.user.name, 'NB_UID':'1500'}
    c.Spawner.pre_spawn_hook = notebook_dir_hook
    from kubernetes import client
    def modify_pod_hook(spawner, pod):
        pod.spec.containers[0].security_context = client.V1SecurityContext(
            privileged=True,
            capabilities=client.V1Capabilities(
                add=['SYS_ADMIN']
            )
        )
        return pod
    c.KubeSpawner.modify_pod_hook = modify_pod_hook
manics commented 4 years ago

Have you mounted a persistent volume under /home/jovyan? This would prevent the directory being moved. You could try changing the mount location ({username} should be expanded): https://github.com/jupyterhub/zero-to-jupyterhub-k8s/blob/9c15a42b1227f3b54826f273f1689e4dc8c8e12e/jupyterhub/values.yaml#L238

mgotham900 commented 4 years ago

I didn't explicitly mentioned the persistent volume to be mounted under /home/jovyan. I just configured the storage as per "Zero to JupyterHub with Kubernetes". However, if we need to explicitly mention the homeMountPath, can you please help me with the configuration. Should it be as below: singleuser: storage: homeMountPath: /home/{username}

Your help is highly appreciated. Thanks in advance

mgotham900 commented 4 years ago

Finally, i made this change and it worked. However, now getting the permission issues for the userhome directory.

Log Message: PermissionError: [Errno 13] Permission denied: '/home/user1/.local'

here is the config.yaml

singleuser: defaultUrl: "/lab" uid: 0 fsGid: 0 extraEnv: CHOWN_HOME: 'yes' CHOWN_HOME_OPTS: -R storage: homeMountPath: /home/{username} extraVolumes:

sampathkethineedi commented 4 years ago

Hi, I need help changing jovyan to {username} at all places. What worked for you?

sampathkethineedi commented 4 years ago

Thanks @mgotham900, this config worked for me

singleuser:
  uid: 0
  extraEnv:
    CHOWN_HOME: 'yes'
  storage:
    homeMountPath: /home/{username}

hub:
  extraConfig: |
    c.Spawner.cmd = ['start.sh','jupyterhub-singleuser','--allow-root']
    c.KubeSpawner.args = ['--allow-root']
    def notebook_dir_hook(spawner):
      spawner.environment = {'NB_USER':spawner.user.name,'NB_UID':'1000'}
    c.Spawner.pre_spawn_hook = notebook_dir_hook
sampathkethineedi commented 4 years ago

Hi, I was able to change the username and home mount but the gitpuller now populates the jovyan home and not the username home