# Create singleuser with custom resource

**URL:** <https://discourse.jupyter.org/t/create-singleuser-with-custom-resource/23370>\
**Category:** Zero to JupyterHub on Kubernetes\
**Tags:** jupyterhub, how-to, help-wanted\
**Created:** [January 11, 2024, 6:21am UTC](https://discourse.jupyter.org/t/create-singleuser-with-custom-resource/23370 "2024-01-11T06:21:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr\_goyal](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mr\_goyal](https://discourse.jupyter.org/u/mr_goyal)\
**Post date:** [January 11, 2024, 6:21am UTC](https://discourse.jupyter.org/t/create-singleuser-with-custom-resource/23370/1 "2024-01-11T06:21:01Z")

</div>

Hi Community,

I am using jupyterhub on kubernetes using [this](https://github.com/jupyterhub/zero-to-jupyterhub-k8s).  
In the helm chart, we can provide resource guarantee and limit for singleuser image to spawn. However, i want it dynamic means user can select resource such as cpu and memory on demand and using that singe user pod will spawn.  
I can see 2 ways to do that

1. profile list
2. form option  
which doesnt fit my use case  
However i can also find below api  
 ![image](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/d/deccf4fbdfc84b49e85ff2820dc0c25654502c1e.png)

which takes dictionary as input for user\_options. How to use this api to provide cpu and memory configs? I can’t find any example for such

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [January 11, 2024, 9:18am UTC](https://discourse.jupyter.org/t/create-singleuser-with-custom-resource/23370/2 "2024-01-11T09:18:18Z")

</div>

Passing user\_options via the API is the same as sending it via a form, but you specify the `user_options` dict directly in the request body, instead of it going through `Spawner.options_from_form` (A form is not required to support user\_options, it is just fine for some or all user\_options to be api-only, if that makes sense for your deployment).

`user_options` is available in `self.user_options` in Spawner.start, so you can extend that to handle whatever `user_options` you want to define in your Spawner subclass. For example:

```python
from kubespawner import KubeSpawner
 
class MySpawner(KubeSpawner):
    async def start(self):
        # process any user_options
        if "mem_guarantee" in self.user_options:
            self.mem_guarantee = self.user_options["mem_guarantee"]
        # continue with start
        return await super().start()

c.JupyterHub.spawner_class = MySpawner

```

which would allow you to:

```python
requests.post('{hub_url}/hub/api/users/servers/', data=json.dumps{"mem_guarantee": "1G"})

```

---

<div class="post-metadata">

**Author:** ![mr\_goyal](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mr\_goyal](https://discourse.jupyter.org/u/mr_goyal)\
**Post date:** [January 11, 2024, 10:10am UTC](https://discourse.jupyter.org/t/create-singleuser-with-custom-resource/23370/3 "2024-01-11T10:10:29Z")

</div>

so with above additional changes . I also have to call my spawner instead of kubespawner. Ex -  
`c.MySpawner.namespace = os.environ.get("POD_NAMESPACE", "default")`

instead of  
`c.KubeSpawner.namespace = os.environ.get("POD_NAMESPACE", "default")`

in all places in [zero-to-jupyterhub-k8s/jupyterhub/files/hub/jupyterhub\_config.py at 53ff33b286b35852dca3aea628f0fe976276e1a5 · jupyterhub/zero-to-jupyterhub-k8s · GitHub](https://github.com/jupyterhub/zero-to-jupyterhub-k8s/blob/53ff33b286b35852dca3aea628f0fe976276e1a5/jupyterhub/files/hub/jupyterhub_config.py) file?

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [January 12, 2024, 2:02pm UTC](https://discourse.jupyter.org/t/create-singleuser-with-custom-resource/23370/4 "2024-01-12T14:02:44Z")

</div>

You don’t need to change anything in your config to use a custom subclass. Config loading follows class inheritance, so you can set base Spawner config on `c.Spawner`, KubeSpawner-specific config on `c.KubeSpawner`, etc. and MySpawner will load it all since it inherits from those classes.

You would only need to rename KubeSpawner fields to MySpawner if you decided to inherit from the base Spawner class instead of KubeSpawner, so that KubeSpawner was no longer a parent class.

---

<div class="post-metadata">

**Author:** ![bpfrd](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bpfrd/32/10762_2.png) [@bpfrd](https://discourse.jupyter.org/u/bpfrd)\
**Post date:** [January 16, 2024, 8:33am UTC](https://discourse.jupyter.org/t/create-singleuser-with-custom-resource/23370/5 "2024-01-16T08:33:19Z")

</div>

how do you work directly with api?

---

<div class="post-metadata">

**Author:** ![mr\_goyal](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@mr\_goyal](https://discourse.jupyter.org/u/mr_goyal)\
**Post date:** [January 16, 2024, 9:24am UTC](https://discourse.jupyter.org/t/create-singleuser-with-custom-resource/23370/6 "2024-01-16T09:24:00Z")

</div>

i am only spawning jupyterlab using api with custom configuration as json
