Configuring external IDE Spark Connect sessions

Learn about how to configure a Spark Connect Session with Cloudera Data Engineering.

Before you create a Spark Connect Session, perform the following steps:
  1. Deploy a Spark Compute instance through the Anywhere Cloud Marketplace.
  2. Have kubectl access to both the Anywhere Cloud Marketplace cluster and the Cloudera Data Engineering cluster, or ask your cluster administrator to retrieve the root CA certificates from the Kubernetes clusters using kubectl.
  3. Install Python on the local machine where you want to use Spark Connect.
  1. Obtain or create the TLS CA certificate bundle based on your environment's certificate configuration:
    • Cloudera self-signed certificates:
      1. Set the KUBECONFIG environment variable to the path of your cluster kubeconfig file before running kubectl commands.
      2. Open a terminal on your device and run the following command on both the Anywhere Cloud Marketplace cluster and the Cloudera Data Engineering workload cluster to extract the CA certificates:
        kubectl get secret default-awc-tls -n istio-ingress -o jsonpath='{.data.ca\.crt}' | base64 -d
      3. Copy the decoded certificate outputs from both Anywhere Cloud Marketplace cluster and the Cloudera Data Engineering workload cluster and paste them into a single PEM file (for example, ca-bundle.pem).
      4. If you do not have kubectl access to these clusters, ask your cluster administrator to generate and provide this combined PEM file.
    • Custom Certificate Authority (CA):
      1. Request a single PEM file containing the full certificate chain (root and intermediate CAs) from your cluster administrator.
      2. Skip this step if your organization's IT team already distributes these certificates to your local trust store.
  2. Create API access keys in the Anywhere Cloud Console UI.
  3. Save the generated client ID and client secret to your local credentials file.

    Sample credential file:

    [default]
    awc_client_id = [***CLIENT_ID_COPIED_IN_THE_PRECEEDING_STEP***]
    awc_client_secret = [***CLIENT_SECRET_COPIED_IN_THE_PRECEEDING_STEP***]
  4. Create the Cloudera Data Engineering client configuration file and point it to your certificate bundle, credentials file, and endpoints:
    • tls-ca-certs
    • credentials-file
    • de-endpoint
    • awc-endpoint
  5. Save the configuration file. On Unix-like systems, save it to ~/.cde/config.yaml.

    Sample configuration file:

    tls-ca-certs: /Users/username/Downloads/cacert_grpc.pem
    credentials-file: /Users/username/.cde/credentials
    de-endpoint: https://cde-jobs-c007-cde-nov19-1-e78e1a.cde-nov19-1.awcqe2.sandbox21.cloudera.com
    awc-endpoint: https://console.27268-engds2integra.awcqe2.sandbox21.cloudera.com
  6. Download the cdeconnect client tarball and the PySpark tarball from the Job Management UI:
    1. Access Anywhere Cloud Console.
    2. Sign in using your enterprise identity provider.
    3. Click Apps in the left navigation pane on the Anywhere Cloud Console. The list of deployed engines and the associated blueprints is displayed.
    4. In the Engines tab, search for the required Cloudera Data Engineering instance and click on the instance name. A details pane is displayed.
    5. Click on the Cloudera Data Engineering URL available in the URL column. The Cloudera Data Engineering console home page is displayed.
    6. In the left navigation pane, click Sessions.
    7. Click on the Spark Connect session you want to connect to.
    8. Click on the Connect tab.
    9. Click on the CDE Tarball and PySpark tarball links to download them.
  7. Create and activate a virtual environment, then install the downloaded packages:
    python -m venv spark-connect-venv
    . spark-connect-venv/bin/activate
    pip install <path to cde connect tarball you downloded in previous step>
    pip install <path to pyspark tarball you downloded in previous step>
    
    Your virtual env is ready to use now. You can run the python script mentioned in next step to check for connectivity.
  8. Run the following PySpark script to verify local connectivity to the Spark Connect session:
    SESSION_NAME = "[***SESSION_NAME***]"
    from cde import CDESparkConnectSession
    
    # Initialize the Spark Connect Session
    spark = CDESparkConnectSession.builder.sessionName(SESSION_NAME).get()
    
    import pyspark.errors.utils as _pyspark_error_utils
    _pyspark_error_utils._enable_debugging_cache = False
    
    # Single partition, one row — minimal driver↔executor work for a sanity check.
    n = spark.range(1).count()
    
    # Validate the output
    print(f"spark.version={spark.version}")
    print(f"range(1).count()={n}")