自定义用户管理#
本节介绍 JupyterHub 上用户及其权限的管理。
清理用户 pod#
当用户使用 JupyterHub 部署时,他们会在完成后可靠地手动关闭他们的服务器吗?可能不会。因此,最好有一个系统可以在可配置的非活动持续时间或最长时间后关闭不活动的服务器。JupyterHub 使用 jupyterhub-idle-culler 来实现这一功能。
当用户服务器被关闭后,用户在下次访问时将需要重新启动他们的服务器。他们先前会话的内存中状态将会丢失,但已打开的笔记本会定期保存到 .ipynb_checkpoints
文件夹中,通常不会导致工作丢失。
注意
有关 jupyterhub-idle-culler
工作原理的更多详细信息以及您可能希望在用户服务器上设置的其他配置,请参阅其工作原理文档。
要禁用清理功能,请将以下内容放入 config.yaml
中
cull:
enabled: false
默认的清理配置可以在 Helm chart 的 values.yaml 文件中的 cull
部分查看。Helm chart 的配置对应于传递给 jupyterhub-idle-culler 的命令行标志。这些标志以及其他标志的完整文档可以在 jupyterhub-idle-culler 的文档中找到。
为了帮助 jupyterhub-idle-culler
清理用户服务器,您应该考虑配置用户服务器的*内核管理器*来清理空闲内核,否则这些内核会使服务器报告自己为活动状态,而这是 jupyterhub-idle-culler
考虑的因素之一。为此,您可以通过 singleuser.extraFiles
将配置文件挂载到用户服务器。
singleuser:
extraFiles:
# jupyter_notebook_config reference: https://notebook.jupyter.org.cn/en/stable/config.html
jupyter_notebook_config.json:
mountPath: /etc/jupyter/jupyter_notebook_config.json
# data is a YAML structure here but will be rendered to JSON file as our
# file extension is ".json".
data:
MappingKernelManager:
# cull_idle_timeout: timeout (in seconds) after which an idle kernel is
# considered ready to be culled
cull_idle_timeout: 1200 # default: 0
# cull_interval: the interval (in seconds) on which to check for idle
# kernels exceeding the cull timeout value
cull_interval: 120 # default: 300
# cull_connected: whether to consider culling kernels which have one
# or more connections
cull_connected: true # default: false
# cull_busy: whether to consider culling kernels which are currently
# busy running some code
cull_busy: false # default: false
注意
虽然 JupyterHub 自动运行清理过程,但这并不能替代您密切关注集群以确保资源按预期使用。
管理员用户#
JupyterHub 有管理员用户的概念,他们拥有特殊权限。他们可以启动/停止其他用户的服务器,并可选择访问用户的笔记本。他们将在其控制面板中看到一个新的**管理员 (Admin)** 按钮,该按钮将带他们进入一个**管理员面板 (Admin Panel)**,他们可以在那里执行所有这些操作。
您可以在您的 config.yaml
中指定一个管理员用户列表
hub:
config:
Authenticator:
admin_users:
- adminuser1
- adminuser2
默认情况下,管理员可以访问用户的笔记本。如果您希望禁用此功能,请在您的 config.yaml
中使用以下配置
hub:
config:
JupyterHub:
admin_access: false
用户身份验证#
有关在 JupyterHub 中对用户进行身份验证的信息,请参阅身份验证指南。