Configure Ranger for Spark on Kubernetes using Helm
This article shows how to enable Ranger for Spark in Kubernetes using Helm and kubectl.
Prerequisites
-
A Kubernetes cluster (1.32 - 1.34) with access configured through
kubectl. -
Helm (3.8.0 or higher) — a package manager that allows quick deployment of Docker images in Kubernetes.
-
Spark artifacts (Docker images and Helm charts) loaded into your private OCI registry. These artifacts can be found in offline packages, which can be requested from the Arenadata support team. To run Spark on Kubernetes, you need to unpack the following images:
-
hub.arenadata.io/adc-enterprise/spark-operator:<version>
-
hub.arenadata.io/adc-enterprise/spark3:<version>
-
hub.arenadata.io/adc-enterprise/spark4:<version>-java17
-
hub.arenadata.io/adc-enterprise/spark4:<version>-java21
-
hub.arenadata.io/adc-enterprise/charts/spark-apps:<version>
-
hub.arenadata.io/adc-enterprise/charts/spark-operator:<version>
-
-
An ADPS cluster is installed and running. The ADPS version should be compatible with ADH Cloud.
-
An ADH cluster is installed and running. The ADH version should be compatible with ADH Cloud.
-
Spark operator is deployed in Kubernetes according to the instruction.
Deployment steps
Step 1. Create a Ranger service
This guide describes how to create a service via Ranger REST API. Alternatively, you can create a service in the Ranger web UI.
-
Define a service in a JSON file:
ranger-spark-k8s.json{ "isEnabled": true, "type": "hive", "name": "spark_k8s", (1) "displayName": "spark_k8s", "description": "Test service for Spark in Kubernetes", "configs": { "username": "spark", "password": "bigdata", "ranger.plugin.audit.filters": "[ {'accessResult': 'DENIED', 'isAudited': true}, {'actions':['METADATA OPERATION'], 'isAudited': false}, {'users':['hive','hue'],'actions':['SHOW_ROLES'],'isAudited':false} ]", "jdbc.driverClassName": "org.apache.hive.jdbc.HiveDriver", "jdbc.url": "jdbc:hive2://ka-adh-2.ru-central1.internal:10002", "userstore.download.auth.users": "*", "tag.download.auth.users": "*", "policy.download.auth.users": "*" } }1 Name of the service in Ranger. Must be unique. NOTEThe example service configuration includes fields such asusername,password,jdbc.url, andjdbc.driverClassName. These fields are not intended for Spark-Ranger interaction (they are used for fetching metadata from HiveServer2 to provide autocompletion in Ranger UI), however, they are mandatory to satisfy the request validation. Specify dummy field values if you do not use a real HiveServer2. -
Push the defined service to Ranger:
$ curl -u admin:<admin_pwd> -H "Content-Type: application/json" -X POST -d @ranger-spark-k8s.json http://<ranger-admin>:6080/service/public/v2/api/service
Step 2. Create secrets
The scenario assumes that Spark running in Kubernetes communicates with an external ADH cluster. To access the ADH cluster, it is necessary to provide ADH configurations to every Kubernetes pod. A way to do this is through Kubernetes secrets.
-
Create the configuration files (core-site.xml, hdfs-site.xml, hive-site.xml), using the examples below. Use configuration values from your ADH cluster.
core-site.xml<?xml version="1.0"?> <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://adh</value> </property> <property> <name>dfs.nameservices</name> <value>adh</value> </property> <property> <name>hadoop.security.authentication</name> <value>simple</value> </property> <property> <name>dfs.ha.namenodes.adh</name> <value>nn_ka-adh-1,nn_ka-adh-2</value> </property> <property> <name>dfs.namenode.rpc-address.adh.nn_ka-adh-1</name> <value>ka-adh-1.ru-central1.internal:8020</value> </property> <property> <name>dfs.namenode.rpc-address.adh.nn_ka-adh-2</name> <value>ka-adh-2.ru-central1.internal:8020</value> </property> </configuration>hdfs-site.xml<?xml version="1.0"?> <configuration> <property> <name>dfs.nameservices</name> <value>adh</value> </property> <property> <name>dfs.ha.namenodes.adh</name> <value>nn_ka-adh-1,nn_ka-adh-2</value> </property> <property> <name>dfs.namenode.rpc-address.adh.nn_ka-adh-1</name> <value>ka-adh-1.ru-central1.internal:8020</value> </property> <property> <name>dfs.namenode.rpc-address.adh.nn_ka-adh-2</name> <value>ka-adh-2.ru-central1.internal:8020</value> </property> <property> <name>dfs.client.failover.proxy.provider.adh</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ObserverReadProxyProvider</value> </property> </configuration>hive-site.xml<?xml version="1.0"?> <configuration> <property> <name>hive.metastore.uris</name> <value>thrift://ka-adh-3.ru-central1.internal:9083</value> </property> <property> <name>metastore.use.SSL</name> <value>False</value> </property> <property> <name>hive.metastore.sasl.enabled</name> <value>False</value> </property> </configuration> -
Create the secret:
$ kubectl create secret generic hadoop-conf -n spark-application-min --from-file=core-site.xml --from-file=hdfs-site.xml --from-file=hive-site.xml -
Verify the secret:
$ kubectl get secrets -n spark-application-minThe output:
NAME TYPE DATA AGE hadoop-conf Opaque 3 2d1h
Step 3. Create a test Spark application
In this scenario, Spark in Kubernetes pulls a PySpark application file from HDFS in the ADH cluster. To create a test PySpark application, do the following:
-
Create the test.py file:
from pyspark.sql import SparkSession from pyspark import SparkConf spark = SparkSession.builder \ .appName("Demo_create_db") \ .enableHiveSupport() \ .getOrCreate() df = spark.sql("create database check_ranger") (1) df.show(10,0) spark.sparkContext.stop()1 Creates a new database. RangerSparkExtension detects this event and reports it to Ranger. -
Upload test.py to HDFS:
$ sudo -u hdfs hdfs dfs -put /tmp/test.py /user/konstantin/test.py
Step 4. Submit the Spark application
-
Create a Helm values file spark-submit.yaml:
spark-submit.yamlUnresolved include directive in modules/ROOT/pages/spark/spark-k8s-ranger-helm.adoc - include::example$spark/k8s/spark-submit.yaml[]1 Address of your OCI registry to pull images from. 2 Name of repository in your registry. 3 Test application to run in Kubernetes. 4 Amount of time after which the Spark application deployment is deleted regardless of the execution result. 5 Kubernetes secret with configurations to access an ADH cluster. 6 RangerSparkExtension detects spark.sql()events (like creating a database) and reports them to Ranger.7 Ranger host URL. You can find one in ADCM (Clusters → <ADPS_cluster> → Ranger → Info). 8 Ranger service name. 9 ZooKeeper connection string with chroot used by Ranger. You can find one using zkCli.sh in your ADPS cluster. -
Submit the Spark application using Helm:
$ helm upgrade --install spark-application oci://hub.adsw.io/ng/charts/spark-apps:<version> -f spark-submit.yaml --namespace spark-application-minThe output:
Release "spark-application" does not exist. Installing it now. Pulled: hub.adsw.io/ng/charts/spark-apps:1.41.0 Digest: sha256:73debb0c68945951ec0e0f0ef90ff6f3182184581cfb360157c2b5da47e11cf1 NAME: spark-application LAST DEPLOYED: Fri Sep 18 13:21:15 2026 NAMESPACE: spark-application-min STATUS: deployed REVISION: 1 DESCRIPTION: Install complete TEST SUITE: None
-
Verify the Spark application pods:
$ kubectl get pods -n spark-application-minThe result:
NAME READY STATUS RESTARTS AGE demo-create-db-6c9b31a0b4d0d767-exec-1 1/1 Running 0 3s spark-application-spark-apps-85973ca0b4d0c34b-driver 1/1 Running 0 8s spark-application-spark-apps-l77hq 1/1 Running 0 12s
Once the job completes, the executor pods are deleted and the status of the driver pod changes to
Completed:NAME READY STATUS RESTARTS AGE spark-application-spark-apps-85973ca0b4d0c34b-driver 0/1 Completed 0 7m2s
-
Check the Spark driver logs within the pod:
$ kubectl logs <driver-pod> -n spark-application-min -
Check the Audit page in Ranger Admin web UI. The test database creation is reflected in the list of audit events.
Ranger audit
Ranger audit