মূল বিষয়বস্তুতে যান

ইলামে অ্যাপাচি স্পার্ক কানেক্ট: কনফিগারেশন এবং সংযোগ গাইড

স্পার্ক কানেক্ট কী?

স্পার্ক কানেক্ট জন্য একটি আধুনিক ক্লায়েন্ট-সার্ভার ইন্টারফেস অ্যাপাচি স্পার্ক that enables remote execution of Spark workloads from lightweight clients such as Python, Java, Scala, R, and SQL-based tools. Introduced in Spark 3.4, Spark Connect decouples the Spark client from the Spark runtime, allowing developers to ইন্টারেক্টিভ ডেটা অ্যাপ্লিকেশন তৈরি করুন , নোটবুক এবং ড্যাশবোর্ডগুলি স্থানীয়ভাবে পুরো স্পার্ক ইঞ্জিন স্থাপন না করে।

স্পার্ক কানেক্ট লিভারেজ জিআরপিসি-ভিত্তিক যোগাযোগ একটি দূরবর্তী স্পার্ক সার্ভারের সাথে ইন্টারঅ্যাক্ট করতে, ডেটা ইঞ্জিনিয়ারিং, ডেটা সায়েন্স এবং বিশ্লেষণ কর্মপ্রবাহের জন্য নমনীয়তা, উন্নত সুরক্ষা এবং সরলীকৃত অবকাঠামো সরবরাহ করে।

এটা very similar to Ilum’s approach to Spark microservices, যেখানে স্পার্ক উপাদানগুলি ধারক করা হয় এবং গতিশীল পরিষেবা হিসাবে উন্মুক্ত হয়। ব্যবহৃত নকশা কুবারনেটসে পাইস্পার্ক মাইক্রোসার্ভিস মোতায়েন করা হচ্ছে : উভয়ই ক্লায়েন্ট সাইডে সম্পূর্ণ ক্লাস্টার সেটআপ ছাড়াই স্পার্কে স্কেলেবল, স্টেটলেস এবং সুরক্ষিত অ্যাক্সেস সক্ষম করে।

Why use Spark Connect on Kubernetes?

Traditional Spark submission often requires complex local setups (Java, Hadoop binaries, exact Spark versions). Spark Connect eliminates this "dependency hell."

বৈশিষ্ট্য Traditional Spark Submission (স্পার্ক-সাবমিট ) স্পার্ক কানেক্ট
স্থাপত্য Monolithic (Driver runs on client or cluster edge)Decoupled (Client is separate from Server)
Client RequirementsHeavy (Requires Java, Spark binaries, Hadoop configs)Lightweight (Only Python/Go/Scala library required)
Network ProtocolCustom RPC (Sensitive to version mismatch)gRPC (Standard, version-agnostic, firewall-friendly)
Iteration SpeedSlow (Build & Deploy jars)Fast (Interactive, REPL-style development)
Language Supportlimited to JVM/PythonPolyglot (Python, Scala, Go, Rust, etc.)
Feature Overview

For a deeper dive into how Ilum leverages this for multi-tenancy, see our Architecture Documentation.

ইলুমে, স্পার্ক কানেক্ট আমাদের মাইক্রোসার্ভিস-ভিত্তিক স্পার্ক আর্কিটেকচারের সাথে প্রাকৃতিকভাবে সারিবদ্ধ হয়। আপনি একটি স্ট্যান্ডার্ড কাজ হিসাবে একটি স্পার্ক কানেক্ট সার্ভার স্থাপন করতে পারেন এবং পডের নাম, পড আইপি বা কুবারনেটসের মাধ্যমে প্রকাশিত কোনও পরিষেবা ব্যবহার করে বিভিন্ন সংযোগ পদ্ধতির মাধ্যমে এটি অ্যাক্সেস করতে পারেন।


Prepare Your Client Environment

Before connecting, you need a lightweight client library. Unlike traditional Spark, you do not need a local JVM or Hadoop installation.

Python (PySpark)

Install PySpark with Connect support (Spark 4 / Python 3.10+)
pip install pyspark[connect]==4.0.1 grpcio-status

Scala (sbt)

For Scala applications, add the Spark Connect client dependency:

libraryDependencies += "org.apache.spark" % %  "spark-connect-client-jvm" %  "4.0.1"

Spark SQL CLI

You can also use the generic Spark SQL CLI to connect remotely:

/path/to/spark/bin/spark-sql --remote "sc://<ilum-cluster-address>:15002"

নোট : Always match your client library version (e.g., 4.0.1; fallback 3.5.7) with the Spark version running on your Ilum cluster.


Ilum UI এর মাধ্যমে অ্যাপাচি স্পার্ক কানেক্ট ইনস্ট্যান্স তৈরি করা হচ্ছে

ওয়েব ইউআই ব্যবহার করে আপনার ইলাম ক্লাস্টারে চাকরি হিসাবে স্পার্ক কানেক্ট সার্ভার চালু করতে এই পদক্ষেপগুলি অনুসরণ করুন:

  1. Start a New Spark Job: Log in to the Ilum UI and navigate to the Jobs section. Click on নতুন চাকরি একটি নতুন স্পার্ক কাজ তৈরি করতে।

  2. Job Name: Enter a recognizable name for the job (e.g., স্পার্ক কানেক্ট সার্ভার ) ইউআইতে পরে এটি সনাক্ত করতে।

  3. Main Class: Set the job's main class to:

    org.apache.spark.sql.connect.service.SparkConnectServer 

    This is the built-in Spark class that starts the Spark Connect server process, enabling remote connectivity to Spark clusters.

  4. Spark Configuration: Go to the Configuration tab/section for the job. Add the following Spark property to ensure the Spark Connect server code is available:

Key: স্পার্ক.জারস.প্যাকেজস

মান : org.apache.spark:spark-connect_2.13:4.0.1

This configuration instructs Spark to fetch the Spark Connect library from Maven when the job starts.

  1. (Optional) Label the Pod: If you plan to expose this Spark Connect server via a Kubernetes Service, add a label to the Spark driver pod:

    • Key: spark.kubernetes.driver.label.type
    • মান : স্পার্ককানেক্ট

    This will tag the Spark Connect server's pod with a label প্রকার=স্পার্ককানেক্ট for easy service selection.

  2. Submit the Job: Click জমা . ইলাম স্পার্কের কাজটি ক্লাস্টারে মোতায়েন করবে। অল্প সময় পর রানিং জব লিস্টে দেখতে হবে কাজটি।

  3. Verify the Server is Running: Wait for the job status to become "Running". You can check the job's logs for a message indicating Spark Connect has started (e.g., a log line mentioning port 15002). Once running, the Spark Connect server is listening for client connections on the default port 15002 .

Job form with Spark Connect option

Spark Connect server link

Missing Spark Connect Dependency?

If your job fails immediately, ensure you added স্পার্ক.জারস.প্যাকেজস with the correct version.


স্পার্ক কানেক্ট সার্ভারের সাথে সংযোগ করা হচ্ছে

একবার স্পার্ক কানেক্ট সার্ভারটি চালু হলে, আপনি স্পার্ক কানেক্ট URL ব্যবহার করে কোনও স্পার্ক ক্লায়েন্ট (যেমন, PySpark, Spark শেল, sparklyr, ইত্যাদি) থেকে এটির সাথে সংযোগ করতে পারেন ( sc://... ). আপনার নেটওয়ার্ক সেটআপের উপর নির্ভর করে নীচে বিভিন্ন সংযোগ পদ্ধতি রয়েছে:

If your environment allows DNS resolution of pod names (for example, your client is within the cluster or can resolve the cluster's internal DNS), you can connect using the pod's DNS name. Kubernetes assigns each pod a DNS name of the form <pod-name>। <namespace>.pod.cluster.local ( Kubernetes DNS ). This DNS name resolves to the pod's IP address inside the cluster.

পদক্ষেপ:

  • Find the Pod Name: In the Ilum UI, locate the Spark Connect job you started. Note the driver pod name (Ilum may show it in the job details or logs). It will be something like চাকরি-xxxxxx-ড্রাইভার (সঠিক বিন্যাস পৃথক হতে পারে)।
  • Construct the URL: Use the pod's fully qualified DNS name. For example, if the pod name is চাকরি-abc123-ড্রাইভার এতে ডিফল্ট নামস্থান, ঠিকানা হবে:
    sc://job-abc123-driver.default.pod.cluster.local:15002 
  • Connect via Spark Client: Use this URL in your SparkSession builder or Spark shell. For example, in PySpark you can do:
    notebook.ipynb
    থেকে পাইস্পার্ক . এসকিউএল আমদানি স্পার্কসেশন 

    স্ফুলিঙ্গ = স্পার্কসেশন . builder. দূরবর্তী (
    "sc://job-abc123-driver.default.pod.cluster.local:15002"
    ) . getOrCreate ( )

This will create a Spark session that connects remotely to the Spark Connect server at the given DNS address. Ensure that your environment's DNS can resolve .pod.cluster.local ঠিকানা (সাধারণত কেবল তখনই সত্য যদি ক্লাস্টারের মধ্যে বা ভিপিএন এর মাধ্যমে ক্লাস্টার নেটওয়ার্কে চলমান থাকে)।

Connection via Pod DNS

টিপ

নোট : This is crucial for managing your Apache Spark applications. If your client is running inside the same namespace in the cluster, you might not need the full domain. For instance, just sc://job-abc123-driver:15002 could work due to Kubernetes' DNS search path. However, using the full পড.ক্লাস্টার.লোকাল নেমস্পেস সহ ঠিকানা সবচেয়ে স্পষ্ট এবং নির্ভরযোগ্য পদ্ধতি।


পরিষ্কারের কাজ

আপনার স্পার্ক কানেক্ট সেশন (গুলি) শেষ করার পরে, সংস্থানগুলি মুক্ত করতে এবং অনাথ সংযোগগুলি এড়াতে নিম্নলিখিত ক্লিনআপ পদক্ষেপগুলি সম্পাদন করুন:

  1. Stop the Spark Connect Job: In the Ilum UI, navigate to the running Spark Connect job and click থামান বা বন্ধ . This will shut down the Spark Connect server process on the cluster. Confirm that the job's status changes to stopped/finished. (If you forget this step, the Spark Connect server will keep running and occupying cluster resources, impacting your spark application performance.)

  2. Terminate Port-Forward Sessions: If you used Kubectl পোর্ট-ফরোয়ার্ড , go to the terminal where it's running and press Ctrl+C পোর্ট-ফরওয়ার্ডিং শেষ করতে। এটি টানেলটি বন্ধ করে দেয় এবং আপনার স্থানীয় বন্দরটি মুক্ত করে। আপনি যদি পটভূমিতে পোর্ট-ফরোয়ার্ড চালান তবে সেই প্রক্রিয়াটি হত্যা করতে ভুলবেন না।

  3. Delete Kubernetes Service (if created): If you exposed a Service for Spark Connect, remove it when it's no longer needed. You can delete it with:

    Kubectl মুছে ফেলুন পরিষেবা স্পার্ক-কানেক্ট-সার্ভিস -এন ডিফল্ট 

    প্রতিস্থাপন স্পার্ক-কানেক্ট-সার্ভিস and namespace as appropriate. This ensures you don't leave an open network endpoint in the cluster. (If you set up a LoadBalancer, deleting the Service will also release the external IP/port. If you used a NodePort, it frees that port on the nodes for other uses.)

পরিষ্কার করে, আপনি নিশ্চিত করেন যে আপনার স্পার্ক কানেক্ট ব্যবহারের সাথে সম্পর্কিত কোনও বিপথগামী প্রক্রিয়া বা পোর্টগুলি খোলা নেই, আপনার স্পার্ক ক্লাস্টারে সংস্থানগুলি অপ্টিমাইজ করে।


Troubleshooting Spark Connect Issues

Here are solutions to the most common errors when connecting to Spark on Kubernetes.

How to fix "Connection Refused" on port 15002?

If your client fails with ConnectionRefusedErrorবা UNAVAILABLE:

Cause: The client cannot reach the Spark Driver pod. This is usually a networking issue, not a Spark issue.

সমাধান :

  1. Check Job Status: Is the job actually RUNNINGএতে Ilum UI ?
  2. Check Network Access:
    • If you are outside the cluster (e.g., local laptop), you cannot use the Pod IP directly. You must use Kubectl পোর্ট-ফরোয়ার্ড (Method 3) or a NodePort/LoadBalancer Service (Method 4).
  3. Verify Port: Ensure you are connecting to 15002 (Spark Connect), not 4040 (Spark UI).
  4. Test Connection: Run nc -vz localhost 15002 (if using port-forward).
How to resolve "Name or service not known" (DNS Error)?

Cause: Your local machine doesn't know how to resolve Kubernetes internal DNS names like job-xyz.default.pod.cluster.local.

সমাধান :

  • Option A:ব্যবহার Kubectl পোর্ট-ফরোয়ার্ড and connect to sc://localhost:15002 .
  • Option B: Connect using the Pod IP directly (only works if you are on the same VPN/VPC).
  • Option C: Configure your local /etc/hosts to point the DNS name to 127.0.0.1 (combined with port forwarding).
How to fix "Pod not found" during port-forwarding?

Cause: Spark Driver pods are ephemeral. If you restart the job, the pod name changes (e.g., from job-abc-driverকরতে job-xyz-driver).

সমাধান :

  • Always check the current driver pod name in the Ilum UI or via kubectl get pods -l spark-role=driver.
  • একটি ব্যবহার করুন সেবা (Method 4) to get a stable hostname that doesn't change between restarts.
Error: "Client version mismatch" or "Unsupported Protocol"

Cause: You are trying to connect a Spark 3.4 client to a Spark 3.5 server (or vice versa).

সমাধান : Check your client version:

pip show pyspark

It must match the Ilum cluster version (e.g., both must be 3.5.x).

Error: "ModuleNotFoundError: No module named 'grpc'"

Cause: The grpcio-status library is missing. It is a required optional dependency for Spark Connect.

সমাধান :

pip install grpcio-status

এই গাইডটি অনুসরণ করে, আপনার সক্ষম হওয়া উচিত ইলামে একটি স্পার্ক কানেক্ট সার্ভার কনফিগার করুন এবং বিভিন্ন পদ্ধতির মাধ্যমে এটির সাথে সংযোগ স্থাপন করুন। ইলাম ইউআই স্পার্ক কানেক্ট উদাহরণটি স্থাপন করা সহজ করে তোলে এবং উপরের কৌশলগুলির সাহায্যে আপনি কুবারনেটস ক্লাস্টারের ভিতরে বা দূরবর্তীভাবে কাজ করছেন কিনা তা আপনি এটি অ্যাক্সেস করতে পারেন। হ্যাপি কানেক্টিং!