question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regarding c.KubeSpawner.environment and the EnvVar structure's valueFrom field

See original GitHub issue

I tried

hub:
  extraConfig:
    jupyterlab: |
      c.KubeSpawner.extra_container_config = {
        "env": [{
          "name": "MY_POD_IP",
          "valueFrom": {
            "fieldRef": {
              "fieldPath": "status.podIP"
            }
          }
        }]
      }

But this will overwrite the default env, and cause error. Any way to append env instead of replace all env?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
abinetcommented, Mar 20, 2019

Thank you @consideRatio! Last point was really the hit.

Here is my solution for now:

hub:
  extraConfig:
    ipaddress: |
      from kubernetes import client

      def modify_pod_hook(spawner, pod):
          pod.spec.containers[0].env.append(client.V1EnvVar("MY_POD_IP", None, client.V1EnvVarSource(None, client.V1ObjectFieldSelector(None, "status.podIP"))))
          return pod
      c.KubeSpawner.modify_pod_hook = modify_pod_hook

0reactions
1ambdacommented, Jun 2, 2021

In case of resources, you can use V1ResourceFieldSelector for example,

      from kubernetes import client

      def modify_pod_hook(spawner, pod):
          pod.spec.containers[0].env.append(client.V1EnvVar("MY_POD_IP", None, client.V1EnvVarSource(field_ref = client.V1ObjectFieldSelector(field_path = "status.podIP"))))
          pod.spec.containers[0].env.append(client.V1EnvVar("MY_POD_NAME", None, client.V1EnvVarSource(field_ref = client.V1ObjectFieldSelector(field_path = "metadata.name"))))
          pod.spec.containers[0].env.append(client.V1EnvVar("MY_CPU_REQUEST", None, client.V1EnvVarSource(resource_field_ref = client.V1ResourceFieldSelector(resource = "requests.cpu"))))
          pod.spec.containers[0].env.append(client.V1EnvVar("MY_CPU_LIMIT", None, client.V1EnvVarSource(resource_field_ref = client.V1ResourceFieldSelector(resource = "limits.cpu"))))
          pod.spec.containers[0].env.append(client.V1EnvVar("MY_MEMORY_REQUEST", None, client.V1EnvVarSource(resource_field_ref = client.V1ResourceFieldSelector(resource = "requests.memory"))))
          pod.spec.containers[0].env.append(client.V1EnvVar("MY_MEMORY_LIMIT", None, client.V1EnvVarSource(resource_field_ref = client.V1ResourceFieldSelector(resource = "limits.memory"))))
          return pod

      c.KubeSpawner.modify_pod_hook = modify_pod_hook
Read more comments on GitHub >

github_iconTop Results From Across the Web

jupyterhub_config.py - Kubespawner - Read the Docs
A JupyterHub spawner that spawn pods in a Kubernetes Cluster. Each server spawned by a user will have its own KubeSpawner instance. after_pod_created_hook...
Read more >
Add environment variable from k8s secret to notebook in ...
Basic idea is to use c.KubeSpawner.modify_pod_hook to add the variable to the pod specification. hub: extraConfig: ipaddress: | from kubernetes ...
Read more >
Zero to JupyterHub - Read the Docs
Step Zero: Kubernetes on Microsoft Azure Container Service (AKS) . ... c.KubeSpawner.cmd = ['jupyter-labhub'].
Read more >
containers.goffinet.org.pdf - GitLab
lorsque l'on doit la faire évoluer. C'est pourquoi Kubernetes a également été conçu pour servir de plate-forme et favoriser la.
Read more >
Advanced Platform Development with Kubernetes: Enabling ...
Leverage Kubernetes for the rapid adoption of emerging technologies. Kubernetes is the future of enterprise platform dev...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found