Run dbt Core on Spark (Kubernetes)
This guide explains how to set up dbt Coreসাথে অ্যাপাচি স্পার্ক running on a Kubernetes cluster. Using Ilum as the execution engine, you can run scalable data transformation pipelines directly on your data lake.
You have two primary ways to connect dbt to Spark on Ilum:
Thrift Server vs. Spark Connect
| বৈশিষ্ট্য | Method 1: Spark Thrift Server (Legacy) | Method 2: Spark Connect (Modern) |
|---|---|---|
| Protocol | JDBC/ODBC (via HiveDriver) | gRPC (via Spark Connect) |
| Connection Type | পদ্ধতি: মিতব্যয়িতা | পদ্ধতি: সেশন |
| স্থাপত্য | Requires a dedicated Thrift Server pod | Connects directly to Spark Driver |
| Performance | Higher latency (row-based serialization) | High performance (Arrow-based) |
| এর জন্য সেরা | BI Tools (Tableau, PowerBI), Legacy apps | Data Engineering, Python/dbt pipelines |
For a deep dive into the architecture, check out our Spark Connect on Kubernetes Guide.
পূর্বশর্ত
Before starting, ensure your development environment is ready:
- Kubernetes Cluster : You need a running K8s cluster (GKE, EKS, AKS, or Minikube).
- Tools:
- হেলম (for deploying Ilum).
- কুবেক্টল (configured to access your cluster).
- Python 3.8+ (for running dbt Core).
- Knowledge: Basic understanding of dbt projects and Spark concepts.
How to Configure dbt with Spark on Kubernetes
Choose your preferred connection method:
- Method 1: Thrift Server
- Method 2: Spark Connect
Step 1: Deploy Spark Thrift Server
Deploy Ilum with the SQL module (acting as a scalable Thrift server) and Hive Metastore enabled:
রেপো যোগ করুন https://charts.ilum.cloud
Helm installation il and ile/el \
--সেট ilum-Hive-metastore.enabled=true \
--set ilum-core.metastore.enabled=true \
--set ilum-core.metastore.type=hive \
--সেট ilum-sql.enabled=true \
--সেট ilum-core.sql.সক্ষম=সত্য
Step 2: Connect to the Thrift Service
1. Identify the service:
কুবেক্টল সেবা পান
এর নামে "এসকিউএল-থ্রিফ্ট-বাইনারি" দিয়ে পরিষেবাটি সন্ধান করুন।
2. Port-forward:
কুবেক্টল পোর্ট-ফরোয়ার্ড এসভিসি / আইএলইউএম-এসকিউএল-থ্রিফ্ট-বাইনারি 10009: 10009
এটি থ্রিফ্ট সার্ভারকে এখানে উপলব্ধ করে তোলে লোকালহোস্ট:10009 .
3. Test with Beeline (optional):
Beline -u "jdbc:hive2://localhost:10009/default"
চালনা:
দেখান টেবিল ;
একটি খালি তালিকা বা বিদ্যমান টেবিল আশা করুন।
Configuring and Running dbt
1. Clean Environment (if needed):
পিপ আনইনস্টল ডিবিটি-স্পার্ক পাইস্পার্ক -ওয়াই
2. Install dbt and dependencies:
pip install pyspark==3.5.7
পিআইপি ইনস্টল ডিবিটি-কোর
পিপ ইনস্টল "ডিবিটি-স্পার্ক [পাইহাইভ, সেশন]"
pip install --upgrade thrift
3. Verify installation:
ডিবিটি --সংস্করণ
Create dbt Project
1. Initialize a dbt project:
DBT init ilum_dbt_project
2. Answer the setup prompts:
Which database? 1 (spark)
host: localhost
Desired authentication method: 3 (thrift)
port: 10009
schema: default
threads: 1
This creates the ilum_dbt_project directory and a profiles.yml file in ~/.dbt/.
Configure dbt for Ilum
সম্পাদনা ~/.dbt/profiles.yml to include both Thrift and Spark Connect targets:
ilum_dbt_project :
লক্ষ্য : মিতব্যয়িতা # Default target
আউটপুট :
মিতব্যয়িতা :
টাইপ : স্ফুলিঙ্গ
পদ্ধতি : মিতব্যয়িতা
আয়োজক : লোকালহোস্ট
পোর্ট : 10009
স্কীমা : ডিফল্ট
থ্রেডসমূহ : 1
connect_retries : 5
connect_timeout : 60
connect_args :
ইউআরএল : "jdbc:hive2://localhost:10009/default; পরিবহনমোড = বাইনারি; হাইভ.সার্ভার 2.ট্রান্সপোর্ট.মোড = বাইনারি"
ড্রাইভার : "org.apache.hive.jdbc.HiveDriver"
অথ : "কেউ না"
spark_connect:
টাইপ : স্ফুলিঙ্গ
পদ্ধতি : সুসংবদ্ধ
আয়োজক : লোকালহোস্ট
পোর্ট : 15002
স্কীমা : ডিফল্ট
থ্রেডসমূহ : 1
Switch between targets:
# Use Thrift (default)
dbt run
# Use Spark Connect
dbt run --target spark_connect
# Or set default in dbt_project.yml
# target: spark_connect
-
টেস্ট সংযোগ:
Debug dbtসিডি ilum_dbt_project
ডিবিটি ডিবাগথ্রিফ্ট সার্ভারের সাথে একটি সফল সংযোগ নির্দেশ করে কোনও ত্রুটি উপস্থিত না হওয়া নিশ্চিত করুন।
Create a Model to Write Data
-
মডেল তৈরি করুন:
-
মডেল/sample_data.sqlমডেল/sample_data.sql{{ কনফিগারেশন ( বাস্তবায়িত = 'টেবিল' ) }}
নির্বাচন
আইডি ,
নাম
থেকে (
মানসমূহ
( 1 , 'অ্যালিস' ) ,
( 2 , 'বব' )
) হিসেবে t ( আইডি , নাম ) -
রান মডেল:
Run sample_datadbt run --select sample_data
Create a Model to Read Data
-
মডেল তৈরি করুন:
-
মডেল/read_data.sqlমডেল/read_data.sql{{ কনফিগারেশন ( বাস্তবায়িত = 'টেবিল' ) }}
নির্বাচন
আইডি ,
নাম ,
দৈর্ঘ্য ( নাম ) হিসেবে name_length
থেকে {{ রেফ ( 'sample_data' ) }} -
রান মডেল:
Run read_datadbt run --select read_data
Verify Results
1. Monitor Job in Ilum UI:
-
Access the Ilum UI (URL provided in your Ilum setup, e.g. port-forward)
-
Navigate to the Jobs section
-
Look for the job named
ilum-sql-spark-engine -
Check job status, logs, and execution details to confirm successful processing
2. Query with Beeline:
Beline -u "jdbc:hive2://localhost:10009/default"3. Run query:
নির্বাচন * থেকে ডিফল্ট . read_data ;Expected output:
+----+-----+------------+
| আইডি | নাম | name_length|
+----+-----+------------+
| 1 | অ্যালিস | 5 |
| 2 | বব | 3 |
+----+-----+------------+
স্পার্ক কানেক্ট is the recommended way for modern data engineering teams to run dbt on Kubernetes. It eliminates the need for a heavy intermediate Thrift Server, reducing costs and complexity.
Step 1: Deploy Spark Connect Job
-
Ilum UI তে লগ ইন করুন
-
Navigate to Workloads → কাজ খণ্ড
-
Click "New Job"বোতাম
-
Configure the job:
- নাম:
spark-connect-dbt - Job Type: Select Spark Connect Job
- নাম:
-
Add Spark Connect dependency (if needed):
Most Spark distributions don't include Spark Connect by default. You'll need to add it as a package dependency.
- Click the কনফিগারেশন tab
- এতে প্যারামিটার section, click Add Parameter
- Add the following parameter:
Key মান স্পার্ক.জারস.প্যাকেজসorg.apache.spark:spark-connect_2.12:3.5.7নোটপ্রতিস্থাপন
2.12with your Scala version and3.5.7with your Spark version to match your environment. -
Click Submit
The server starts successfully when you see this in the logs:
Spark Connect server started at: 0:0:0:0:0:0:0:0%0:15002
স্পার্ক কানেক্ট সার্ভারের সাথে সংযোগ করা হচ্ছে
Get the Connection URL
After the job starts, Ilum provides a Spark Connect URL on the job details page.
The URL format is: sc://job-xxxxx-driver-svc:15002
Port-Forward for Local Access
To connect from your local machine, forward the driver pod's port:
-
Find the driver pod name from the লগ tab in Ilum UI
যেমন: If URL is
sc://job-20250807-1557-ablr2a52vxd-driver-svc:15002,
the pod name isjob-20250807-1557-ablr2a52vxd-driver(remove-svcsuffix) -
পোর্ট-ফরোয়ার্ড:
Port Forwardkubectl port-forward <driver-pod-name> 15002:15002Keep this terminal window open.
Create dbt Project
একটি ডিবিটি প্রকল্প শুরু করুন (যদি প্রয়োজন হয়):
DBT init ilum_dbt_spark_connect_project
Answer the setup prompts:
Which database? 1 (spark)
host: localhost
Desired authentication method: 4 (session) #or 3 if u can't see session
port: 15002
schema: default
threads: 1
This creates the ilum_dbt_spark_connect_project directory and updates ~/.dbt/profiles.yml .
Configure dbt for Spark Connect
If you followed the Thrift setup above, your ~/.dbt/profiles.yml already has both targets configured. You can use the same ilum_dbt_project profile.
To use Spark Connect, simply specify the target:
cd ilum_dbt_project # Use the same project as Thrift
dbt debug --target spark_connect
dbt run --target spark_connect
Or create a separate project (if you prefer isolation):
সম্পাদনা ~/.dbt/profiles.yml :
ilum_dbt_spark_connect_project :
লক্ষ্য : দেব
আউটপুট :
দেব :
টাইপ : স্ফুলিঙ্গ
পদ্ধতি : সুসংবদ্ধ
আয়োজক : লোকালহোস্ট
পোর্ট : 15002
স্কীমা : ডিফল্ট
থ্রেডসমূহ : 1
Test the connection:
cd ..
সিডি ilum_dbt_spark_connect_project
ডিবিটি ডিবাগ
Recommended approach: Use one dbt project with multiple targets (as shown in the Thrift section). This allows you to switch between Thrift and Spark Connect without maintaining separate projects.
You should see successful connection messages.
Create a Model to Write Data
-
মডেল তৈরি করুন:
-
মডেল/sample_data_connect.sqlমডেল/sample_data_connect.sql{{ কনফিগারেশন ( বাস্তবায়িত = 'টেবিল' ) }}
নির্বাচন
আইডি ,
নাম
থেকে (
মানসমূহ
( 1 , 'পিটার' ) ,
( 2 , 'জন' )
) হিসেবে t ( আইডি , নাম ) -
রান মডেল:
Run sample_data_connectdbt run --select sample_data_connect --target spark_connect
Create a Model to Read Data
-
মডেল তৈরি করুন:
-
মডেল/read_data_connect.sqlমডেল/read_data_connect.sql{{ কনফিগারেশন ( বাস্তবায়িত = 'টেবিল' ) }}
নির্বাচন
আইডি ,
নাম ,
দৈর্ঘ্য ( নাম ) হিসেবে name_length
থেকে {{ রেফ ( 'sample_data_connect' ) }} -
রান মডেল:
Run read_data_connectdbt run --select read_data_connect --target spark_connectনোটঐ
--target spark_connectflag ensures dbt uses the Spark Connect configuration instead of the default Thrift target.
Verify Results
-
ইলম ইউআইতে মনিটর জব:
- ইলাম ইউআই অ্যাক্সেস করুন (আপনার আইলুম সেটআপে সরবরাহ করা ইউআরএল, উদাঃ পোর্ট-ফরোয়ার্ড)।
- জবস বিভাগে নেভিগেট করুন।
- স্পার্ক-কানেক্ট নামের চাকরিটি সন্ধান করুন।
- সফল প্রক্রিয়াকরণ নিশ্চিত করতে কাজের স্থিতি, লগ এবং সম্পাদনের বিশদ পরীক্ষা করুন।
-
ডিবিটি জবে ডেটা মুদ্রণ করুন: স্পার্ক গুদামে অবতরণ করা ডেটা যাচাই করতে (উদাঃ,
স্পার্ক-গুদাম/read_data_connectআপনার প্রকল্প ডিরেক্টরির সাথে সম্পর্কিত), একটি ডিবিটি ম্যাক্রো তৈরি করুন এবং ক্যোয়ারী এবং মুদ্রণের জন্য একটি কাস্টম অপারেশন চালানread_data_connecttable’s contents during the dbt job.আপনার ডিবিটি প্রকল্প ডিরেক্টরিতে একটি ম্যাক্রো ফাইল তৈরি করুন:
-
ম্যাক্রো/print_table.sql:ম্যাক্রো/print_table.sql{ % ম্যাক্রো print_table ( table_name ) % }
{ % সেট ক্যোয়ারী % }
নির্বাচন * থেকে {{ রেফ ( table_name ) }}
{ % সমাপ্তি % }
{ % কি লগ ( এর জন্য টেবিলের বিষয়বস্তু মুদ্রণ করা' ~ table_name ~ ':' , সত্য ) % }
{ % সেট ফলাফল = run_query ( ক্যোয়ারী ) % }
{ % যদি ফলাফল % }
{ % জন্য সারি মধ্যে ফলাফল % }
{ % কি লগ ( সারি , সত্য ) % }
{ % এন্ডফর % }
{ % অন্য % }
{ % কি লগ ( 'কোনও তথ্য পাওয়া যায়নি' ~ table_name , সত্য ) % }
{ % এন্ডআইএফ % }
{ % এন্ডম্যাক্রো % }মুদ্রণ করতে ম্যাক্রো চালান
read_data_connectআপনার ডিবিটি মডেলের পরে টেবিল:Run Macroডিবিটি রান-অপারেশন print_table --আর্গস '{"table_name": "read_data_connect"}'ঐ
ডিবিটি রান-অপারেশনকমান্ড ম্যাক্রো কার্যকর করে, ক্যোয়ারিং করেread_data_connectসারণী এবং এর বিষয়বস্তু লগিং করা। ডিবিটি লগ বা কনসোলে প্রত্যাশিত আউটপুট:read_data_connect জন্য টেবিল বিষয়বস্তু মুদ্রণ:
<অ্যাগেট.রো: (2, 'জন', 4)>
<অ্যাগেট.রো: (1, 'পিটার', 5)>নোটThe output appears in the dbt logs or console by default in dbt 1.9.4. For more detailed logs, you can use:
Debug Macroডিবিটি রান-অপারেশন print_table --args '{"table_name": "read_data_connect"}' --log-level debug
-
Troubleshooting dbt-spark Connections
Common issues when connecting dbt to Spark on Kubernetes:
Error: "ThriftTransportException: Could not connect to localhost:10009"
Cause: The port forwarding tunnel is down or the Thrift Server pod is not running. সমাধান :
- Check if the Thrift pod is running:
kubectl get pods -l app.kubernetes.io/name=ilum-sql - Restart port-forwarding:
কুবেক্টল পোর্ট-ফরোয়ার্ড এসভিসি / আইএলইউএম-এসকিউএল-থ্রিফ্ট-বাইনারি 10009: 10009
Error: "grpc._channel._InactiveRpcError: failed to connect to all addresses"
Cause: Your local dbt client cannot reach the Spark Connect gRPC port (15002). সমাধান :
- Ensure you have port-forwarded the Driver Pod, not the Service (unless using NodePort).
- Verify you are using
পদ্ধতি: সেশনমধ্যেprofiles.yml.
Error: "AnalysisException: Table or view not found"
Cause: Hive Metastore connectivity issue. সমাধান :
- Ensure
ilum-core.metastore.enabled=truewas set during Helm install. - Check if the schema (database) exists in Spark:
spark.sql("SHOW DATABASES").show()
অর্কেস্ট্রেশন
For production orchestration using Apache Airflow, see the dedicated guide: Orchestrate dbt with Airflow