Objects

Module: kubespawner.objects

Helper methods for generating k8s API objects.

kubespawner.objects.make_pod(name, cmd, port, image_spec, image_pull_policy, image_pull_secret=None, node_selector=None, run_as_uid=None, fs_gid=None, run_privileged=False, env={}, working_dir=None, volumes=[], volume_mounts=[], labels={}, annotations={}, cpu_limit=None, cpu_guarantee=None, mem_limit=None, mem_guarantee=None, extra_resource_limits=None, extra_resource_guarantees=None, lifecycle_hooks=None, init_containers=None, service_account=None, extra_container_config=None, extra_pod_config=None, extra_containers=None)

Make a k8s pod specification for running a user notebook.

Parameters:
  • name: Name of pod. Must be unique within the namespace the object is going to be created in. Must be a valid DNS label.
  • image_spec: Image specification - usually a image name and tag in the form of image_name:tag. Same thing you would use with docker commandline arguments
  • image_pull_policy: Image pull policy - one of ‘Always’, ‘IfNotPresent’ or ‘Never’. Decides when kubernetes will check for a newer version of image and pull it when running a pod.
  • image_pull_secret: Image pull secret - Default is None – set to your secret name to pull from private docker registry.
  • port: Port the notebook server is going to be listening on
  • cmd: The command used to execute the singleuser server.
  • node_selector: Dictionary Selector to match nodes where to launch the Pods
  • run_as_uid: The UID used to run single-user pods. The default is to run as the user specified in the Dockerfile, if this is set to None.
  • fs_gid The gid that will own any fresh volumes mounted into this pod, if using volume types that support this (such as GCE). This should be a group that the uid the process is running as should be a member of, so that it can read / write to the volumes mounted.
  • run_privileged: Whether the container should be run in privileged mode.
  • env: Dictionary of environment variables.
  • volumes: List of dictionaries containing the volumes of various types this pod will be using. See k8s documentation about volumes on how to specify these
  • volume_mounts: List of dictionaries mapping paths in the container and the volume( specified in volumes) that should be mounted on them. See the k8s documentaiton for more details
  • working_dir: String specifying the working directory for the notebook container
  • labels: Labels to add to the spawned pod.
  • annotations: Annotations to add to the spawned pod.
  • cpu_limit: Float specifying the max number of CPU cores the user’s pod is allowed to use.
  • cpu_guarentee: Float specifying the max number of CPU cores the user’s pod is guaranteed to have access to, by the scheduler.
  • mem_limit: String specifying the max amount of RAM the user’s pod is allowed to use. String instead of float/int since common suffixes are allowed
  • mem_guarantee: String specifying the max amount of RAM the user’s pod is guaranteed to have access to. String ins loat/int since common suffixes are allowed
  • lifecycle_hooks: Dictionary of lifecycle hooks
  • init_containers: List of initialization containers belonging to the pod.
  • service_account: Service account to mount on the pod. None disables mounting
  • extra_container_config: Extra configuration (e.g. envFrom) for notebook container which is not covered by parameters above.
  • extra_pod_config: Extra configuration (e.g. tolerations) for pod which is not covered by parameters above.
  • extra_containers: Extra containers besides notebook container. Used for some housekeeping jobs (e.g. crontab).
kubespawner.objects.make_pvc(name, storage_class, access_modes, storage, labels, annotations={})

Make a k8s pvc specification for running a user notebook.

Parameters:
  • name: Name of persistent volume claim. Must be unique within the namespace the object is going to be created in. Must be a valid DNS label.
  • storage_class String of the name of the k8s Storage Class to use.
  • access_modes: A list of specifying what access mode the pod should have towards the pvc
  • storage The ammount of storage needed for the pvc