Spark, Trino, and the lakehouse
straight from notebooks.
Four scenarios: what the notebook image already ships, the connection to a Spark cluster, queries to Trino, and reading and writing lakehouse tables. Each one covers: the chart default, the block commented line by line when there is configuration, and the verification.
Notebooks communicate with the rest of the platform through kernel libraries and the Spark configuration mounted in each server by the tdp-jupyter chart. The kernel already includes PySpark and clients for Trino, S3, Iceberg, Delta Lake, Kafka and other databases. The tdpSparkIntegration block connects notebooks to a Spark cluster. The Hub's own database is covered in JupyterLab Configuration.
Your environment
If you fill in your environment details here, the examples and commands on the page use what you provided. The namespace, the release name and the values file are your choices, not the chart's.
Scenarios
- 1 · How it connects
- 2 · Spark cluster
- 3 · Trino queries
- 4 · Lakehouse
What the image includes: kernel libraries, the Spark distribution and network access allowed for servers.
JupyterHub connects to the rest of the platform through what ships in the notebook image: the kernel libraries and the Spark distribution. By default, nothing needs to be configured: Spark runs in local mode, inside the user server, and server network egress already allows the components used by these libraries. The following tabs cover the Spark cluster, Trino queries and the lakehouse (Iceberg and Delta Lake on S3 storage).
Before connecting any integration, you want to know what notebooks can already do without configuration. Each user server runs the TDP notebook image, with an isolated Python kernel that includes data libraries and platform component clients, and the Spark distribution from the TDP Spark image.
pyspark and pyarrow in the kernel. The Spark distribution in SPARK_HOME, copied from the TDP Spark image, at the same Spark version as the tdp-spark chart of the same TDP release. By default, Spark runs in local mode (local[*]).
delta-spark, pyiceberg (with PyArrow, Hive and S3 support) and boto3.
trino, sqlalchemy-trino, jupysql, sqlalchemy and duckdb.
clickhouse-driver, clickhouse-connect, psycopg2-binary, mysql-connector-python, pymongo, pyodbc, oracledb and confluent-kafka.
pandas, polars, matplotlib, seaborn, tabulate and great_expectations.
The servers' NetworkPolicy allows egress to DNS, cluster pods, external addresses and Spark, Trino, Hive Metastore, Kafka and Ozone services. See Security - JupyterLab for details.
The user server and the Spark configuration
- Hub. Starts each user's server with the notebook image, Spark configuration and environment variables from the values file.
- User server. The Python kernel includes PySpark, delta-spark, pyiceberg, boto3, Trino, Kafka and ClickHouse clients, and clients for other databases. The Spark distribution comes from the TDP Spark image. Chart default:
Local Spark (local[*]). (tdp-jupyter.singleuser.extraEnv.SPARK_MASTER_URL) - Spark Configuration. Generated by the chart with spark-defaults.conf and an environment script, mounted in each server at /opt/bitnami/spark/conf. Chart default:
spark.master local[*]. (tdpSparkIntegration.configMap)
Any other integration using one of these libraries works the same way: the notebook imports the library and connects to the service through its cluster address.
Names outside DNS
When a service used by notebooks has a name that cluster DNS cannot resolve, user servers can receive custom /etc/hosts entries:
1tdp-jupyter:2singleuser:3 extraPodConfig:4 hostAliases:5 - ip: "<IP_ADDRESS>"6 hostnames:7 - "<COMPONENT_HOSTNAME>"
Fields added to the pod definition of each user server.
- Extra pod configuration (linha 3). Fields added to the pod definition of each user server.
- IP (linha 5). The address to which the names below point.
- Names (linha 7). Names that resolve to this IP address inside servers.
Replace local Spark with a standalone Spark cluster, with workers reaching the driver.
This tab connects notebooks to a Spark cluster. By default, Spark runs in local mode, inside the user server. In Spark, the driver is the process that coordinates an application, and the executors are the processes that do the work, on the workers of a cluster. Notebooks run Spark, and the data volume needs more than the user server can handle. You connect notebooks to a separately installed standalone Spark cluster, for example with the tdp-spark chart: the driver stays in the user server and executors run on cluster workers. The tdpSparkIntegration block points Spark configuration to the master, the process that manages the standalone cluster. Each pod's IP is injected as the driver address, so workers always reach it through its IP without relying on name resolution. Workers need an ingress rule in the servers' NetworkPolicy.
Integration disabled (tdpSparkIntegration.enabled: false): spark.master is local[*] and Spark runs inside the user server.
The <RELEASE_NAME>-spark-integration ConfigMap, mounted in each server at /opt/bitnami/spark/conf (SPARK_CONF_DIR), with spark-defaults.conf and an environment script read when the server starts.
Only for the Spark cluster: a standalone Spark cluster reachable from the notebooks namespace. The JupyterHub chart does not install Spark.
Where the Spark executors run
Where Spark runs
- Hub. Starts each user's server with the notebook image, Spark configuration and environment variables from the values file.
- User server. The Python kernel includes PySpark, delta-spark, pyiceberg, boto3, Trino, Kafka and ClickHouse clients, and clients for other databases. The Spark distribution comes from the TDP Spark image. Chart default:
Local Spark (local[*]). (tdp-jupyter.singleuser.extraEnv.SPARK_MASTER_URL) - Spark Configuration. Generated by the chart with spark-defaults.conf and an environment script, mounted in each server at /opt/bitnami/spark/conf. Chart default:
spark.master local[*]. (tdpSparkIntegration.configMap) - Spark master. In local mode, Spark runs inside the user server and does not use a master. Chart default:
disabled. (tdpSparkIntegration.enabled) - Spark workers. In local mode, Spark runs inside the user server and does not use workers. (
tdp-jupyter.singleuser.networkPolicy.ingress)
Where Spark runs: In the user server (default)
- Hub. Starts each user's server with the notebook image, Spark configuration and environment variables from the values file.
- User server. The Python kernel includes PySpark, delta-spark, pyiceberg, boto3, Trino, Kafka and ClickHouse clients, and clients for other databases. The Spark distribution comes from the TDP Spark image. Chart default:
Local Spark (local[*]). (tdp-jupyter.singleuser.extraEnv.SPARK_MASTER_URL) - Spark Configuration. Generated by the chart with spark-defaults.conf and an environment script, mounted in each server at /opt/bitnami/spark/conf. Chart default:
spark.master local[*]. (tdpSparkIntegration.configMap) - Spark master. In local mode, Spark runs inside the user server and does not use a master. Chart default:
disabled. (tdpSparkIntegration.enabled) - Spark workers. In local mode, Spark runs inside the user server and does not use workers. (
tdp-jupyter.singleuser.networkPolicy.ingress)
Where Spark runs: In a Spark cluster
- Hub. Starts each user's server with the notebook image, Spark configuration and environment variables from the values file.
- User server. The Python kernel includes PySpark, delta-spark, pyiceberg, boto3, Trino, Kafka and ClickHouse clients, and clients for other databases. The Spark distribution comes from the TDP Spark image. Chart default:
Local Spark (local[*]). (tdp-jupyter.singleuser.extraEnv.SPARK_MASTER_URL) - Spark Configuration. Generated by the chart with spark-defaults.conf and an environment script, mounted in each server at /opt/bitnami/spark/conf. Chart default:
spark.master local[*]. (tdpSparkIntegration.configMap) - Spark master. The master of a separately installed standalone Spark cluster, for example with the chart tdp-spark. Chart default:
disabled. (tdpSparkIntegration.enabled) - Spark workers. Run executors and connect back to the driver, in the user server, on the driver and block manager ports. The servers' NetworkPolicy must allow them in. (
tdp-jupyter.singleuser.networkPolicy.ingress)
Local Spark. This is what the chart starts without a values file: Spark runs inside the user server and uses its CPU and memory (singleuser.cpu and singleuser.memory), without a Spark cluster. Local Spark: Best suited when there is no Spark cluster or the processing fits in the CPU and memory of the user server. In a notebook with the PySpark Python kernel:
import os
from pyspark.sql import SparkSession
spark = (
SparkSession.builder
.appName("my-notebook")
.master(os.environ.get("SPARK_MASTER_URL", "local[*]"))
.getOrCreate()
)
print("Spark", spark.version, "master", spark.sparkContext.master)
spark.range(5).show()
spark.stop()
The printed line shows local[*] as master. Without .master(...), Spark uses spark.master from the mounted spark-defaults.conf.
To use a Spark cluster, select In a Spark cluster above.
Spark cluster. Executors run on the cluster workers, and the driver stays in the user server. Spark cluster: Best suited when the data volume needs more than the user server can handle and there is a standalone Spark cluster reachable from the notebooks namespace.
The master Service, in the tdp-spark chart, is tdp-spark-master-svc when the Spark release has the chart name. With another release name, it is <SPARK_RELEASE>-spark-master-svc, or <SPARK_RELEASE>-master-svc when that name already contains spark.
1tdpSparkIntegration:2enabled: true3configMap:4 sparkConfig:5 "spark.master": "spark://<SPARK_MASTER_SERVICE>.<NAMESPACE>.svc.cluster.local:7077"6 "spark.driver.host": ""7 "spark.driver.port": "2222"8 "spark.driver.bindAddress": "0.0.0.0"9 "spark.blockManager.port": "7777"10 "spark.executor.instances": "2"11 "spark.executor.memory": "4g"12 "spark.executor.cores": "3"1314tdp-jupyter:15singleuser:16 extraEnv:17 SPARK_MASTER_URL: "spark://<SPARK_MASTER_SERVICE>.<NAMESPACE>.svc.cluster.local:7077"18 SPARK_DRIVER_HOST:19 valueFrom:20 fieldRef:21 fieldPath: status.podIP22 SPARK_DRIVER_BIND_ADDRESS: "0.0.0.0"23 SPARK_DRIVER_PORT: "2222"24 SPARK_BLOCKMANAGER_PORT: "7777"25 SPARK_CONNECT_PORT: "0"26 networkPolicy:27 enabled: true28 ingress:29 - from:30 - podSelector:31 matchLabels:32 app.kubernetes.io/component: worker33 app.kubernetes.io/instance: <SPARK_RELEASE>34 app.kubernetes.io/name: spark35 ports:36 - protocol: TCP37 port: 222238 - protocol: TCP39 port: 7777
tdpSparkIntegration is outside the chart prefix, at the root of the values file.
- At the root (linha 1). tdpSparkIntegration is outside the chart prefix, at the root of the values file.
- Enables integration (linha 2). The Spark configuration mounted in servers now points to the cluster.
- Master (linha 5). The master address of your Spark cluster. When empty, the chart builds the address using the JupyterHub release name. Therefore, set it when enabling a cluster.
- Empty driver host (linha 6). When empty, the line is left out of spark-defaults.conf, and PySpark uses the pod IP from SPARK_DRIVER_HOST. Never set a fixed name or IP here with multiple users.
- Driver ports (linha 7). The driver port and, on line 9, the block manager port. These are the ports workers use to connect back to the driver.
- Executors (linha 10). How many executors each session requests from the cluster, with memory and cores for each.
- Master in the environment (linha 17). The same master address, in the variable read by notebooks.
- Pod IP (linha 21). Injects the server pod IP as the driver address, through the Kubernetes Downward API.
- Spark Connect port (linha 25). "0" makes Spark Connect use any available port, avoiding conflicts when multiple notebooks run at the same time.
- Worker ingress (linha 28). Without this rule, workers cannot reach the driver and the Spark application times out.
- Spark release (linha 33). The release name of your Spark cluster.
- Allowed ports (linha 37). The same driver and block manager ports as on lines 7 and 9.
Write the values file
Replace the Spark master Service, namespace and release with those of your cluster.
If you already have a JupyterHub values file, add the blocks to it. tdpSparkIntegration.configMap.sparkConfig and singleuser.extraEnv are maps: keys you set are merged with other chart defaults. Other Spark properties go in sparkConfig, alongside those in the example.
Apply to the release
The same command installs and upgrades.
helm upgrade --install <RELEASE_NAME> oci://registry.tecnisys.com.br/tdp/charts/tdp-jupyter \
--version 3.0.3 \
-n <NAMESPACE> --create-namespace --timeout 10m \
-f <VALUES_FILE>
Restart the user server
The server reads Spark configuration and environment variables only when it starts.
After helm upgrade, each user with a running server stops and restarts it: File → Hub Control Panel → Stop My Server, then Start My Server.
Test the Spark session
The session points to the cluster master and runs a job.
In a notebook with the PySpark Python kernel:
import os
from pyspark.sql import SparkSession
spark = (
SparkSession.builder
.appName("my-notebook")
.master(os.environ.get("SPARK_MASTER_URL", "local[*]"))
.getOrCreate()
)
print("Spark", spark.version, "master", spark.sparkContext.master)
spark.range(5).show()
spark.stop()
Call spark.stop() when finished so the cluster releases executors. With integration enabled, the chart also includes a test notebook in a ConfigMap. Download it and upload it through JupyterLab:
kubectl -n <NAMESPACE> get configmap tdp-jupyter-spark-test \
-o jsonpath='{.data.spark-integration-test\.ipynb}' > spark-integration-test.ipynb
Success criteria
spark:// address as master, spark.range(5).show() prints the table and, while the session is open, the application appears in the Spark master UI.If the job does not finish
Check the Spark configuration generated by the chart and environment variables received by the server (pods are named <RELEASE_NAME>-notebook-<user>), and see When something goes wrong:
kubectl -n <NAMESPACE> get configmap <RELEASE_NAME>-spark-integration \
-o jsonpath='{.data.spark-defaults\.conf}'
kubectl -n <NAMESPACE> get pods -l component=singleuser-server
kubectl -n <NAMESPACE> exec <POD_NAME> -- env | grep SPARK_
Write event logs to History ServerOpcional
Only if the Spark chart's History Server is enabled.
Drivers running outside the Spark chart, such as the notebook driver, must write event logs to the same directory read by History Server. Add spark.eventLog.enabled and spark.eventLog.dir to tdpSparkIntegration.configMap.sparkConfig, with the directory configured in the Spark chart.
Trino clients in the kernel and where to find the address and authentication.
You want to query Trino from a notebook, in Python or SQL directly in cells. The kernel already includes clients, and egress to Trino is already allowed by the servers' NetworkPolicy: you only need the Trino address and, if login is required, credentials.
trino (Python client), sqlalchemy-trino and jupysql, for SQL in cells.
Egress allowed to the Trino coordinator.
The notebook querying Trino
- Hub. Starts each user's server with the notebook image, Spark configuration and environment variables from the values file.
- User server. The Python kernel includes PySpark, delta-spark, pyiceberg, boto3, Trino, Kafka and ClickHouse clients, and clients for other databases. The Spark distribution comes from the TDP Spark image. Chart default:
Local Spark (local[*]). (tdp-jupyter.singleuser.extraEnv.SPARK_MASTER_URL) - Spark Configuration. Generated by the chart with spark-defaults.conf and an environment script, mounted in each server at /opt/bitnami/spark/conf. Chart default:
spark.master local[*]. (tdpSparkIntegration.configMap) - Trino. Queried by the kernel's trino, sqlalchemy-trino and jupysql clients. Egress to it is already allowed by the servers' NetworkPolicy.
The coordinator address, port and authentication are in Trino Configuration, and other Trino connections are covered in Integrations - Trino.
Iceberg and Delta tables in S3 storage, and keys with Ozone security.
Notebooks read and write lakehouse tables: Iceberg and Delta, in TDP S3-compatible storage, with the catalog in Hive Metastore. The kernel already includes libraries, and Delta tables maintained by the Delta Lake chart are read and written by Spark and JupyterHub. With Ozone security enabled, notebooks also need S3 access keys.
delta-spark for Delta Lake with Spark; pyiceberg, with PyArrow, Hive and S3 support; and boto3 for S3.
Egress allowed to Hive Metastore and Ozone S3 Gateway.
With it enabled, Spark drivers running outside Spark pods, such as user servers, need AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, read from the ozone-s3-credentials Secret.
The notebook, S3 and the catalog
- Hub. Starts each user's server with the notebook image, Spark configuration and environment variables from the values file.
- User server. The Python kernel includes PySpark, delta-spark, pyiceberg, boto3, Trino, Kafka and ClickHouse clients, and clients for other databases. The Spark distribution comes from the TDP Spark image. Chart default:
Local Spark (local[*]). (tdp-jupyter.singleuser.extraEnv.SPARK_MASTER_URL) - Spark Configuration. Generated by the chart with spark-defaults.conf and an environment script, mounted in each server at /opt/bitnami/spark/conf. Chart default:
spark.master local[*]. (tdpSparkIntegration.configMap) - S3-compatible storage. Where Iceberg and Delta tables are stored. With Ozone security enabled, S3 Gateway validates keys.
- Hive Metastore. The table catalog. Egress to it is already allowed by the servers' NetworkPolicy.
- ozone-s3-credentials Secret. With Ozone security enabled, Spark drivers running outside Spark pods, such as user servers, need the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY variables from this Secret.
The ozone-s3-credentials Secret is created when Ozone security is enabled, as in Upgrade via Argo CD. Tables and catalogs are covered in Integrations - Iceberg, Integrations - Delta Lake and Integrations - Apache Ozone.
When something goes wrong
Troubleshooting
Paste the error message or choose a symptom. The answer includes the cause, what to do and the command.
- Connecting to /<pod-ip>:2222 timed out. Cause: The servers' NetworkPolicy blocks ingress from Spark workers, which need to connect back to the driver. What to do: Add the worker ingress rule to the servers' networkPolicy (scenario 2) and upgrade the release.
- java.net.UnknownHostException with the pod name. Cause: spark.driver.host resolves to the pod name rather than its IP address. What to do: Leave spark.driver.host empty in sparkConfig and inject SPARK_DRIVER_HOST through the Downward API, with fieldPath: status.podIP (scenario 2).
- Connection to the Spark cluster fails. Cause: A NetworkPolicy blocks traffic, or the Spark cluster is not reachable from the notebooks namespace. What to do: Check NetworkPolicies and whether the Spark cluster is reachable. The configuration generated by the chart shows the master used by servers.
- BindException on the Spark Connect port. Cause: Several notebooks run at the same time and Spark's default ports are already in use. What to do: Set SPARK_CONNECT_PORT to "0" in singleuser.extraEnv, as in the scenario 2 example: Spark Connect then uses any available port.
- CANNOT_MODIFY_CONFIG warnings. Cause: spark.driver.host or JARs were passed through SparkSession.builder.config(). What to do: Pass spark.driver.host and JARs through PYSPARK_SUBMIT_ARGS, before importing PySpark.
- Spark configuration changes do not appear in the notebook. Cause: The user server reads Spark configuration and environment variables only when it starts. What to do: After helm upgrade, each user stops and restarts their server: File, Hub Control Panel, Stop My Server, then Start My Server.
- The notebook job does not appear in History Server. Cause: The driver, running in the user server, does not write event logs to the directory read by History Server. What to do: Add spark.eventLog.enabled and spark.eventLog.dir to tdpSparkIntegration.configMap.sparkConfig (scenario 2).
- S3 access denied with Ozone security enabled. Cause: With Ozone security enabled, Spark drivers running outside Spark pods need the keys from the ozone-s3-credentials Secret. What to do: Provide the user server with AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the ozone-s3-credentials Secret (scenario 4).
- Other problem. Cause: Start with server pods and the Spark variables they receive. What to do: Server pods are named <RELEASE_NAME>-notebook-<user>. SPARK_ variables show what the server received.
Integration parameters
The chart prefix is already filled in. Keys without a prefix belong at the root of the values file.
18 of 18 parameters
| Parameter | Description | Chart default |
|---|---|---|
tdpSparkIntegration.enabledIntegration | Points servers' Spark configuration to a Spark cluster | false |
tdpSparkIntegration.configMap.nameIntegration | Spark configuration ConfigMap name. When empty, <RELEASE_NAME>-spark-integration | "" |
tdpSparkIntegration.configMap.sparkConfig."spark.master"Integration | Master address. When empty, local[*] with integration disabled and, with it enabled, this chart release's master: set it when enabling a cluster | "" |
tdpSparkIntegration.configMap.sparkConfig."spark.driver.host"Integration | Driver address. When empty, PySpark uses the pod IP from SPARK_DRIVER_HOST | "" |
tdpSparkIntegration.configMap.sparkConfig."spark.driver.port"Integration | Driver port | 2222 |
tdpSparkIntegration.configMap.sparkConfig."spark.blockManager.port"Integration | Block manager port | 7777 |
tdpSparkIntegration.configMap.sparkConfig."spark.executor.instances"Integration | Executors per session | 3 |
tdpSparkIntegration.configMap.sparkConfig."spark.executor.memory"Integration | Memory per executor | 2g |
tdpSparkIntegration.configMap.sparkConfig."spark.executor.cores"Integration | Cores per executor | 2 |
tdp-jupyter.singleuser.extraEnv.SPARK_MASTER_URLEnvironment | Master address read by notebooks | local[*] |
tdp-jupyter.singleuser.extraEnv.SPARK_DRIVER_PORTEnvironment | Driver port | 2222 |
tdp-jupyter.singleuser.extraEnv.SPARK_BLOCKMANAGER_PORTEnvironment | Block manager port | 7777 |
tdp-jupyter.singleuser.extraEnv.SPARK_DRIVER_MEMORYEnvironment | Driver memory | 4g |
tdp-jupyter.singleuser.extraEnv.SPARK_EXECUTOR_MEMORYEnvironment | Executor memory | 4g |
tdp-jupyter.singleuser.extraEnv.SPARK_HOMEEnvironment | Spark distribution in the image | /opt/bitnami/spark |
tdp-jupyter.singleuser.networkPolicy.ingressNetwork | Server ingress rules. With a Spark cluster, allows workers to reach the driver | not set |
tdp-jupyter.singleuser.networkPolicy.egressNetwork | Server egress rules. Setting the list in your file replaces the entire list | DNS, cluster pods, external addresses and TDP component services |
tdp-jupyter.singleuser.extraPodConfig.hostAliasesNetwork | /etc/hosts entries in user servers | not set |
Next steps
Configuration
JupyterLab Configuration
First steps, resources, Hub database and exposure through a URL.