Skip to main content

Notebook Kernel Spec

This guide will walk you through using the Notebook Admin client to create and manage Kernel types that will be available to users in the Notebook Lab.

Creating Kernel Images

First, you need to create a kernel image. This is a Docker image that contains the software and configuration for the Kernel.

The apply method in the example will delete all existing kernel images and replace them with the provided list.

See KernelImage documentation for more details.

import h2o_notebook

from h2o_notebook.clients.kernel_image.kernel_image_config import KernelImageConfig
from h2o_notebook.clients.kernel_image.type import KernelImageType

notebook = h2o_notebook.login()

kernel_images = [
KernelImageConfig(
kernel_image_id="python",
kernel_image_type=KernelImageType.TYPE_PYTHON,
image="gcr.io/vorvan/h2oai/h2o-kernel-py:0.4.0",
display_name="Python",
disabled=False,
),
KernelImageConfig(
kernel_image_id="r",
kernel_image_type=KernelImageType.TYPE_R,
image="gcr.io/vorvan/h2oai/h2o-kernel-r:0.4.0",
display_name="R",
disabled=False,
),
KernelImageConfig(
kernel_image_id="python-spark",
kernel_image_type=KernelImageType.TYPE_SPARK_PYTHON,
image="gcr.io/vorvan/h2oai/h2o-kernel-pyspark:0.4.0",
display_name="Spark - Python",
disabled=False,
),
KernelImageConfig(
kernel_image_id="r-spark",
kernel_image_type=KernelImageType.TYPE_SPARK_R,
image="gcr.io/vorvan/h2oai/h2o-kernel-sparkr:0.4.0",
display_name="Spark - R",
disabled=False,
)
]

notebook.kernel_image_client.apply_kernel_images(kernel_images)

Creating Kernel Templates

Next, you need to create a template which describes the resources and environmental settings for the kernel.

The apply method in the example will delete all existing kernel templates and replace them with the provided list.

See KernelTemplate documentation for more details.

import h2o_notebook

from h2o_notebook.clients.kernel_template.kernel_template_config import KernelTemplateConfig

notebook = h2o_notebook.login()

kernel_templates = [
KernelTemplateConfig(
kernel_template_id="small",
gpu=0,
memory_bytes_limit="12Gi",
memory_bytes_request="12Gi",
max_idle_duration="1h",
),
KernelTemplateConfig(
kernel_template_id="medium",
gpu=0,
memory_bytes_limit="32Gi",
memory_bytes_request="32Gi",
max_idle_duration="1h",
),
KernelTemplateConfig(
kernel_template_id="large",
gpu=0,
memory_bytes_limit="128Gi",
memory_bytes_request="128Gi",
max_idle_duration="1h",
),
]

notebook.kernel_template_client.apply_kernel_templates(kernel_templates)

Creating Notebook Kernel Specs

Finally, you need to create a kernel spec which combines the kernel image and kernel template.

The apply method in the example will delete all existing notebook kernel specs and replace them with the provided list.

See NotebookKernelSpec documentation for more details.

import h2o_notebook

from h2o_notebook.clients.notebook_kernel_spec.notebook_kernel_spec_config import NotebookKernelSpecConfig

notebook = h2o_notebook.login()

notebook_kernel_specs = [
NotebookKernelSpecConfig(
notebook_kernel_spec_id="python",
display_name="Python",
kernel_image_id="python",
kernel_template_id="medium",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="python-l",
display_name="Python [L]",
kernel_image_id="python",
kernel_template_id="large",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="python-xl",
display_name="Python [XL]",
kernel_image_id="python",
kernel_template_id="python-xl",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="r",
display_name="R",
kernel_image_id="r",
kernel_template_id="small",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="python-spark",
display_name="Spark - Python",
kernel_image_id="python-spark",
kernel_template_id="medium",
),
NotebookKernelSpecConfig(
notebook_kernel_spec_id="r-spark",
display_name="Spark - R",
kernel_image_id="r-spark",
kernel_template_id="medium",
)
]

notebook.notebook_kernel_spec_client.apply_notebook_kernel_specs(notebook_kernel_specs)

Applying Kernel Images, Templates, and Specs

To avoid conflicts, you can apply the kernel images, templates, and specs in a single transaction. This will delete all existing kernel images, templates, and specs and replace them with the provided lists.

import h2o_notebook

notebook = h2o_notebook.login()

kernel_images = [
# ...
]

kernel_templates = [
# ...
]

notebook_kernel_specs = [
# ...
]

clients.notebook_kernel_spec_client.apply_kernel_images_templates_notebook_specs(
kernel_image_configs=kernel_images,
kernel_template_configs=kernel_templates,
notebook_kernel_spec_configs=notebook_kernel_specs
)

Feedback