Analytics Azure

Apache Spark 4.3 on Ubuntu 26.04 on Azure User Guide

| Product: Apache Spark 4.3 on Ubuntu 26.04 LTS on Azure

Overview

Apache Spark is an open source engine for large-scale data processing: batch jobs, SQL over files and tables, streaming and machine learning, written in Python, Scala, Java, R or SQL. The cloudimg image delivers Apache Spark 4.3.0 fully installed and running on Ubuntu 26.04 LTS as a ready-to-use standalone cluster: a Spark master and a worker as systemd services on OpenJDK 21, with PySpark on Python 3.14, and the Spark web UI published over HTTPS by nginx behind a password. Every Spark port listens on loopback only, cluster traffic is authenticated with a secret unique to your VM, and the web UI password is made on the first boot of your VM, so the cluster is up and locked down the moment you sign in. cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours.

Apache Spark is licensed under the Apache License 2.0 (/opt/spark/LICENSE and /opt/spark/NOTICE on the image). cloudimg is not affiliated with, endorsed by, or sponsored by the Apache Software Foundation; "Apache", "Apache Spark" and "Spark" are trademarks of the Apache Software Foundation. This image repackages the official Apache Spark release with cloudimg's provisioning and support.

What is included:

  • Apache Spark 4.3.0 (the official spark-4.3.0-bin-hadoop3 release, SHA-512 verified) in /opt/spark, with spark-submit, pyspark, spark-shell and spark-sql on every user's PATH
  • A standalone cluster ready to run jobs: spark-master.service and spark-worker.service, run as the unprivileged spark user, the worker offering every core and nearly all the memory of the VM
  • OpenJDK 21 and Python 3.14 from the Ubuntu 26.04 archive, so PySpark works out of the box
  • nginx in front of the Spark web UI: HTTPS on :443 with a password (the master, the worker and every running application's UI through one address), with :80 redirecting to HTTPS and answering a plain /healthz liveness check
  • Per-VM cluster secret (Spark RPC authentication), web UI password and TLS certificate, all made on first boot. The sign-in details go to the root-only file /root/apache-spark-credentials.txt. No default or shared login ships in the image
  • /srv/spark, a shared work directory for job data that the Spark executors and your users in the spark group can both read and write
  • spark-selftest, a one-command check that the cluster runs Scala and Python jobs
  • cloudimg's support team on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours

Spark master web UI

Prerequisites

An active Azure subscription, an SSH key pair, and a VNet plus subnet in the target region. Standard_B2ms (2 vCPU / 8 GiB RAM) is a good starting point for learning Spark, development and small datasets; choose a larger size for heavier jobs, since the worker uses every core and nearly all the memory the VM has. NSG inbound: allow 22/tcp (SSH, where you submit jobs) from your management network and 443/tcp (the web UI over HTTPS) plus 80/tcp (which redirects to HTTPS) from the people who use the web UI.

Step 1 — Deploy from the Azure Marketplace

Sign in to the Azure Portal, choose Create a resource, search the Marketplace for Apache Spark by cloudimg, and select Create. On Basics pick your subscription, resource group, region and size; under Administrator account choose SSH public key and paste your key; under Inbound port rules allow SSH (22), HTTP (80) and HTTPS (443). Then Review + create and Create.

Step 2 — Deploy from the Azure CLI

# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn cloudimg1647283583153:apache-spark-ubuntu-26-04:default:latest

az vm create \
  --resource-group <your-rg> \
  --name spark \
  --image cloudimg1647283583153:apache-spark-ubuntu-26-04:default:latest \
  --size Standard_B2ms \
  --admin-username azureuser \
  --generate-ssh-keys \
  --public-ip-sku Standard

Open HTTPS (and HTTP, which redirects) to reach the web UI:

az vm open-port --resource-group <your-rg> --name spark --port 443 --priority 900
az vm open-port --resource-group <your-rg> --name spark --port 80  --priority 910

Step 3 — Connect to your VM

ssh azureuser@<vm-public-ip>

The address is on the VM's Overview page in the portal, or from the CLI with az vm show -d -g <your-rg> -n spark --query publicIps -o tsv.

Step 4 — Confirm the cluster is running

The master, the worker and nginx should all report active. Plain HTTP answers the /healthz liveness check and redirects everything else to HTTPS, and HTTPS asks for the password (401 without it). The Spark master (7077), its web UI (8080) and the worker's web UI (8081) listen on loopback only; only nginx and SSH face the network:

systemctl is-active spark-master spark-worker nginx
curl -s  -o /dev/null -w 'healthz        -> %{http_code}\n' http://127.0.0.1/healthz
curl -s  -o /dev/null -w 'http redirect  -> %{http_code} %{redirect_url}\n' http://127.0.0.1/
curl -ks -o /dev/null -w 'https, no auth -> %{http_code}\n' https://127.0.0.1/
sudo ss -tln | awk '{print $4}' | grep -E ':(22|80|443|7077|8080|8081)$' | sort -u

Expected output:

active
active
active
healthz        -> 200
http redirect  -> 301 https://127.0.0.1/
https, no auth -> 401
0.0.0.0:22
0.0.0.0:443
0.0.0.0:80
[::]:22
[::]:443
[::]:80
[::ffff:127.0.0.1]:7077
[::ffff:127.0.0.1]:8080
[::ffff:127.0.0.1]:8081

The cluster's own status, read from the master's JSON endpoint on loopback, shows the worker ALIVE with the VM's cores and memory:

curl -s http://127.0.0.1:8080/json/ | python3 -c 'import json,sys; d=json.load(sys.stdin); print("master", d["url"], d["status"]); [print("worker", w["state"], w["cores"], "cores", w["memory"], "MB") for w in d["workers"]]'

Expected output (the cores and memory follow your VM's size):

master spark://127.0.0.1:7077 ALIVE
worker ALIVE 2 cores 6907 MB

Cluster status, health and listeners

Step 5 — Retrieve your web UI password

On the first boot of every VM, apache-spark-firstboot.service runs before Spark and nginx start. It writes a cluster secret unique to the VM into Spark's configuration, makes the web UI password (nginx keeps only its bcrypt hash), makes a self-signed certificate for the VM's address, adds your administrator account to the spark group, and writes the sign-in details to a root-only file. No shared or default credentials ship in the image.

sudo cat /root/apache-spark-credentials.txt

The file (mode 0600, root only) holds the web UI address, the username (admin), the password and the cluster's master URL:

SPARK_UI_URL=https://<VM address>/
SPARK_UI_USERNAME=admin
SPARK_UI_PASSWORD=<SPARK_UI_PASSWORD>
SPARK_MASTER_URL=spark://127.0.0.1:7077

Per-VM credentials, root-only and masked

You can prove the sign-in round trip from the VM's own shell. This reads the password, asks for the web UI through nginx with it (the master's page comes back), then shows a wrong password is refused (401). The password goes to curl in a private netrc file, never on a command line:

PASS=$(sudo grep '^SPARK_UI_PASSWORD=' /root/apache-spark-credentials.txt | cut -d= -f2-)
N=$(mktemp); chmod 600 "$N"
printf 'machine 127.0.0.1 login admin password %s\n' "$PASS" > "$N"
curl -ks --netrc-file "$N" https://127.0.0.1/ | grep -o 'Spark Master at spark://[^<]*' | head -1
printf 'machine 127.0.0.1 login admin password wrong-99\n' > "$N"
curl -ks --netrc-file "$N" -o /dev/null -w 'wrong password -> %{http_code}\n' https://127.0.0.1/
rm -f "$N"; unset PASS

Expected output:

Spark Master at spark://127.0.0.1:7077
wrong password -> 401

Step 6 — Sign in to the Spark web UI

Browse to https://<vm-public-ip>/. Because the image ships a per-VM self-signed certificate, your browser shows a one-time certificate warning on the first visit: continue past it, or install your own domain's certificate (see Your own domain and certificate below). Your browser then asks for a username and password: enter admin and the password from the credentials file.

The page is the Spark master UI: the cluster's status, its worker with the cores and memory it offers, and the applications that are running and that have finished. Every link stays on the same HTTPS address: the worker's page, and each running application's own UI (its jobs, stages, storage, executors and SQL queries), are proxied through the master, so nothing else needs to be opened in the NSG.

Step 7 — Run your first jobs

Jobs are submitted over SSH. spark-submit, pyspark, spark-shell and spark-sql are on the PATH and already point at this VM's master (spark://127.0.0.1:7077) with its secret, so they need no options. The configuration that holds the secret is readable by root and the spark group only: first boot adds the VM's administrator account to that group. If id does not list spark in your session, log in again (or run newgrp spark).

Start with the built-in self-test, which checks the cluster and runs a Scala job and a PySpark job on it:

spark-selftest

Expected output:

OK master spark://127.0.0.1:7077 is ALIVE with 1 worker(s), 2 cores, 6907 MB
OK SparkPi (Scala) on the cluster: Pi is roughly 3.1416975708487853
OK PySpark on the cluster: sum(1..1000000) = 500000500000
spark-selftest: all checks passed

The Spark executors run as the spark user, not as you, so the files a job reads and the directory it writes to must be ones spark can reach. /srv/spark is made for that: it belongs to the spark group, what you create there stays in the group, and other local users cannot read it. Here is a PySpark job that reads a CSV file, works out revenue by region, prints it and writes the result as Parquet:

mkdir -p /srv/spark/demo && cd /srv/spark/demo
cat > sales.csv <<'CSV'
region,product,units,price
north,widget,12,2.50
south,widget,7,2.50
north,gadget,3,10.00
east,gadget,9,10.00
south,gizmo,15,4.25
east,widget,4,2.50
CSV
cat > sales_report.py <<'PY'
from pyspark.sql import SparkSession, functions as F

spark = SparkSession.builder.appName("sales-report").getOrCreate()
df = spark.read.csv("/srv/spark/demo/sales.csv", header=True, inferSchema=True)
report = (df.withColumn("revenue", F.col("units") * F.col("price"))
            .groupBy("region")
            .agg(F.sum("units").alias("units"), F.round(F.sum("revenue"), 2).alias("revenue"))
            .orderBy(F.desc("revenue")))
report.show()
report.write.mode("overwrite").parquet("/srv/spark/demo/sales_by_region.parquet")
spark.stop()
PY
spark-submit sales_report.py 2>/dev/null
ls /srv/spark/demo/sales_by_region.parquet | head -3

Expected output:

+------+-----+-------+
|region|units|revenue|
+------+-----+-------+
|  east|   13|  100.0|
| south|   22|  81.25|
| north|   15|   60.0|
+------+-----+-------+

_SUCCESS
part-00000-<id>-c000.snappy.parquet

Spark SQL queries the Parquet output directly:

cd /srv/spark/demo
spark-sql -e 'SELECT region, units, revenue FROM parquet.`/srv/spark/demo/sales_by_region.parquet` ORDER BY revenue DESC' 2>/dev/null

Expected output:

east    13  100.0
south   22  81.25
north   15  60.0

And a Scala example from the Spark distribution, estimating pi across the cluster:

spark-submit --class org.apache.spark.examples.SparkPi /opt/spark/examples/jars/spark-examples_2.13-4.3.0.jar 50 2>/dev/null

Expected output (the digits vary from run to run, as they do in spark-selftest):

Pi is roughly 3.1420694284138855

Each of these shows up in the web UI under Completed Applications. While an application runs, its name links to its own UI. The Jobs page shows each job and its stages on a timeline:

A running application's jobs

The SQL / DataFrame tab shows each query and its plan:

A running application's SQL queries

The worker's page shows the executors running on it:

The worker and its executors

For an interactive session, run pyspark (Python) or spark-shell (Scala); the session is itself a cluster application, so it appears in the web UI while it is open. Clean up the example with rm -rf /srv/spark/demo.

Step 8 — Confirm the version and the stack

spark-submit --version 2>&1 | grep -E 'version [0-9]|Using Scala'
head -1 /opt/spark/RELEASE
java -version 2>&1 | head -1
python3 --version
nginx -v

Expected output:

   /___/ .__/\_,_/_/ /_/\_\   version 4.3.0
Using Scala version 2.13.18, OpenJDK 64-Bit Server VM, 21.0.13.1
Spark 4.3.0 (git revision 98bc0212c94) built for Hadoop 3.5.0
openjdk version "21.0.13.1" 2026-11-17
Python 3.14.4
nginx version: nginx/1.28.3 (Ubuntu)

Version and stack

Server components

Component Version Runs as Listens on
Apache Spark master 4.3.0 spark (spark-master.service) 127.0.0.1:7077 (cluster), 127.0.0.1:8080 (web UI)
Apache Spark worker 4.3.0 spark (spark-worker.service) 127.0.0.1:8081 (web UI), a random loopback port
OpenJDK 21 (Ubuntu archive)
Python 3.14 (Ubuntu archive), for PySpark
nginx 1.28 (Ubuntu archive) nginx.service :80 (health check and redirect), :443 (HTTPS web UI)
Ubuntu 26.04 LTS

Filesystem layout

Path What it holds
/opt/spark Apache Spark 4.3.0 (a link to /opt/spark-4.3.0-bin-hadoop3): bin/, sbin/, jars/, python/, examples/, the licence and notice
/opt/spark/conf/spark-defaults.conf Spark's defaults for every job, including this VM's cluster secret (root and the spark group only)
/opt/spark/conf/spark-env.sh The daemons' environment: Java, Python, loopback binding, ports, directories
/srv/spark The shared work directory for job data (group spark)
/var/lib/spark/work The worker's per-application directories (executor output and logs); finished ones are removed after 7 days
/var/log/spark The master's and worker's own logs
/etc/nginx/sites-available/cloudimg-apache-spark The nginx site
/etc/nginx/apache-spark.htpasswd The web UI password, as a bcrypt hash
/etc/nginx/ssl/apache-spark.crt, apache-spark.key The TLS certificate and key (the key is root-only)
/root/apache-spark-credentials.txt The per-VM web UI sign-in (root-only)
/mnt The Azure temporary disk: lost on deallocation, never for data

First-boot service and security model

The image ships with no cluster secret, no usable password and no certificate: they are made on your VM by apache-spark-firstboot.service, which runs once, before the Spark daemons and nginx start. Spark's standalone cluster has no login of its own, so the image closes it in three layers. Every Spark listener binds to loopback, so nothing outside the VM can reach the master or the worker. Spark's RPC authentication (spark.authenticate) is on with the VM's own secret, so a client on the VM that does not hold the secret (a user outside the spark group) cannot submit work. The master's REST submission server (port 6066), which takes jobs without authentication, is switched off. The web UI is published only through nginx, over HTTPS, behind the password.

systemctl status apache-spark-firstboot.service --no-pager | head -3
grep -E '^spark\.(authenticate|master\.rest\.enabled) ' /opt/spark/conf/spark-defaults.conf
sudo grep -c '^spark.authenticate.secret ' /opt/spark/conf/spark-defaults.conf
echo | openssl s_client -connect 127.0.0.1:443 2>/dev/null | openssl x509 -noout -subject -ext subjectAltName
sudo stat -c '%a %U:%G %n' /root/apache-spark-credentials.txt /opt/spark/conf/spark-defaults.conf /etc/nginx/apache-spark.htpasswd /etc/nginx/ssl/apache-spark.key /srv/spark

Expected output: the service active (exited), authentication on and the REST server off, one secret line, a certificate made for this VM's address, and the secrets readable only by their owners:

● apache-spark-firstboot.service - Apache Spark first-boot initialisation (per-VM RPC secret, web UI password and certificate)
     Loaded: loaded (/etc/systemd/system/apache-spark-firstboot.service; enabled; preset: enabled)
     Active: active (exited) since ...
spark.authenticate                true
spark.master.rest.enabled         false
1
subject=CN=<VM address>
X509v3 Subject Alternative Name: 
    IP Address:<VM address>, IP Address:127.0.0.1
600 root:root /root/apache-spark-credentials.txt
640 root:spark /opt/spark/conf/spark-defaults.conf
640 root:www-data /etc/nginx/apache-spark.htpasswd
600 root:root /etc/nginx/ssl/apache-spark.key
2770 spark:spark /srv/spark

A client that does not hold this VM's secret cannot use the cluster. A user who cannot read the configuration has no secret at all, and Spark refuses to start their job (A secret key must be specified). A client with a wrong secret is refused by the master itself: this copies Spark's configuration with a made-up secret and submits a job with it, and the master rejects the handshake, so no result is printed:

D=$(mktemp -d); cp /opt/spark/conf/spark-env.sh "$D/"
sudo sed 's/^spark.authenticate.secret .*/spark.authenticate.secret not-this-vms-secret/' /opt/spark/conf/spark-defaults.conf > "$D/spark-defaults.conf"
OUT=$(SPARK_CONF_DIR="$D" timeout 120 spark-submit --class org.apache.spark.examples.SparkPi /opt/spark/examples/jars/spark-examples_2.13-4.3.0.jar 2 2>&1)
grep -c 'Pi is roughly' <<<"$OUT"; grep -o -m1 'SaslException: DIGEST-MD5: [^.]*' <<<"$OUT"
rm -rf "$D"; unset OUT

Expected output:

0
SaslException: DIGEST-MD5: digest response format violation

First boot and hardening

Giving other users access

A Linux user can run jobs on the cluster once they are in the spark group, which lets them read the cluster secret and work in /srv/spark. Add a user and give them access (they pick up the group at their next login):

sudo adduser <their-username>
sudo usermod -aG spark <their-username>

Anyone in the spark group can submit jobs, and jobs run as spark, so add only people you trust with the cluster and its data. Everyone who uses the web UI shares the one admin login; to give people their own web UI logins, add them to the password file with sudo htpasswd -B /etc/nginx/apache-spark.htpasswd <their-name> and sudo systemctl reload nginx.

Managing the services

sudo systemctl status spark-master --no-pager | head -5

Restart the cluster with sudo systemctl restart spark-master spark-worker, and nginx with sudo systemctl reload nginx. The daemons' logs are in /var/log/spark and journalctl -u spark-master -u spark-worker; an application's executor output is in /var/lib/spark/work/<app-id>/, also linked from the worker's page in the web UI.

The worker offers every core and all but 1 GiB of the VM's memory. After resizing the VM, restart the worker and it offers the new size. To set them yourself, add SPARK_WORKER_CORES or SPARK_WORKER_MEMORY (for example 6g) to /opt/spark/conf/spark-env.sh and restart the worker. Per-job settings such as --executor-memory and --total-executor-cores go on the spark-submit command line or in spark-defaults.conf.

Your own domain and certificate

Point a DNS record (for example spark.example.com) at the VM's public address, then move the self-signed certificate and the credentials file to the name in one step:

sudo cloudimg-set-public-address spark.example.com

Run it with no argument to go back to the VM's public IP, and again whenever the VM's address changes. For a browser-trusted certificate, install one from your CA over the self-signed pair. With Let's Encrypt, once DNS points at the VM and port 80 is open to the internet, certbot's standalone mode briefly stops nginx to answer the challenge on port 80, copies the certificate into place, and saves the same steps for its automatic renewals:

sudo apt-get update && sudo apt-get install -y certbot
sudo certbot certonly --standalone -d spark.example.com \
  --pre-hook 'systemctl stop nginx' --post-hook 'systemctl start nginx' \
  --deploy-hook 'install -m 0644 "$RENEWED_LINEAGE/fullchain.pem" /etc/nginx/ssl/apache-spark.crt && install -m 0600 "$RENEWED_LINEAGE/privkey.pem" /etc/nginx/ssl/apache-spark.key'

A certificate you install yourself is never replaced by the image's tools. To make a fresh self-signed one for another name instead, run sudo apache-spark-tls-cert --force <name> and sudo systemctl reload nginx.

Backup and maintenance

The cluster keeps no state of its own between restarts: what matters is your data in /srv/spark (or wherever your jobs read and write) and your configuration in /opt/spark/conf. Snapshot the OS disk from the Azure portal for a point-in-time copy, or archive the data and configuration:

sudo tar -czf /var/backups/spark-$(date +%F).tar.gz /srv/spark /opt/spark/conf

For larger datasets, keep the data in Azure Blob Storage or Azure Data Lake Storage and read it from your jobs, or attach a data disk and mount it under /srv/spark. Keep the OS current with sudo apt-get update && sudo apt-get upgrade; the image ships with unattended security updates enabled. Read Spark's migration guide before moving to a new Spark version.

Troubleshooting

  • The browser shows a certificate warning. Expected with the self-signed certificate: continue past it, or install your own (above).
  • spark-submit says it cannot read spark-defaults.conf, or the job is refused with a SaslException. Your user is not in the spark group yet, or the session started before it was added: run id, then log in again (or newgrp spark).
  • A job fails with FILE_NOT_EXIST or Permission denied on a file in your home directory. The executors run as spark and cannot read your home: put the job's data in /srv/spark.
  • An application waits with "Initial job has not accepted any resources". Another application holds the cores: check Running Applications in the web UI, or ask for fewer with --total-executor-cores.
  • The worker is missing from the master page. systemctl status spark-worker and journalctl -u spark-worker -n 50 name the reason.

Security recommendations

  • Restrict 22/tcp in the NSG to your management network, and expose 443/tcp (and 80/tcp for the redirect) only to the people who use the web UI.
  • Keep the web UI password somewhere safe, then delete /root/apache-spark-credentials.txt if you no longer need it.
  • Install a browser-trusted certificate on your own domain before sharing the web UI.
  • Add to the spark group only the users you trust to run jobs: membership gives the cluster secret.
  • Keep the Spark ports on loopback. To grow beyond one VM, plan the cluster's network with Spark's security guide (RPC authentication and encryption on every node) rather than opening these ports.

Support

cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours, for deployment, job submission and PySpark setup, Spark SQL, tuning executors and memory, connecting to Azure storage, your own domain and certificates, and upgrades. Email support@cloudimg.co.uk.