Artificial Intelligence (AI) Azure

Ollama GPU on Ubuntu 24.04 on Azure User Guide

| Product: Ollama GPU on Ubuntu 24.04 LTS on Azure

Overview

This guide covers the deployment and configuration of Ollama GPU on Ubuntu 24.04 on Azure using cloudimg Azure Marketplace images. Ollama downloads, quantizes and serves open large language models such as Llama, Mistral, Gemma, Phi, Qwen and DeepSeek with a single command, and exposes a REST API that is also OpenAI chat-completions compatible (/v1/chat/completions).

This image is built for NVIDIA GPU virtual machines. The NVIDIA 580 server driver is installed from Ubuntu's archive with Canonical's prebuilt, signed kernel modules for the Azure kernel: no DKMS, no compiler on the VM and no driver extension to add. Boot the VM on a GPU size and Ollama finds the GPU straight away; nvidia-smi lists it and models run on it.

The image installs the official Ollama 0.40.19 release (pinned at build) to /usr/local/bin/ollama, with Ollama's bundled CUDA runtime libraries, and runs it under systemd. The Ollama server binds to loopback only (127.0.0.1:11434) and has no authentication of its own; nginx is the only network facing service. It terminates TLS on port 443 and enforces HTTP Basic authentication against a bcrypt htpasswd file.

No anonymous access. On the first boot the image generates a per-VM admin credential, writes it into the nginx htpasswd file and generates a self-signed TLS certificate for this VM. Anonymous requests to the model API return HTTP 401; the open GET /api/version and /healthz endpoints stay available for health probes. The credential is written to /root/ollama-credentials.txt (mode 0600, root only).

No model ships in the image. You choose the models you run and pull them on to the VM's disk (Step 7). Each model comes under its own licence.

What is included:

  • The NVIDIA 580 server driver (headless, no X) with Canonical-signed prebuilt modules for the linux-azure kernel, kept in step with kernel updates by Ubuntu's own packages

  • Ollama 0.40.19 at /usr/local/bin/ollama, run under systemd as the unprivileged ollama system user, with its CUDA runtime under /usr/local/lib/ollama and the model store at /var/lib/ollama/models

  • The Ollama server bound to loopback only (127.0.0.1:11434), never directly network exposed

  • nginx terminating TLS on :443 and enforcing htpasswd Basic auth on the model API; GET /api/version and /healthz stay open for health probes

  • Port :80 returns a 301 redirect to HTTPS for every path except an unauthenticated /healthz endpoint (HTTP 200)

  • A per-VM admin credential generated on first boot and stored in /root/ollama-credentials.txt (0600): no shared default password

  • A self-signed TLS certificate generated per VM on first boot; replace it with your own CA-signed certificate for production (Step 10)

  • Ubuntu 24.04 LTS with the latest security patches applied at build time, and unattended security upgrades left on

  • cloudimg's support team on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours

Prerequisites

  • An active Azure subscription, an SSH public key, and a VNet and subnet in the target region

  • GPU quota for the size you deploy, in that region. GPU families have their own vCPU quota, often 0 by default: check it under Subscriptions > Usage + quotas (for Standard_NC4as_T4_v3 the family is Standard NCASv3_T4 Family) and request more there if needed

  • A subscription to the Ollama GPU listing on Azure Marketplace

Recommended virtual machine size: Standard_NC4as_T4_v3 (4 vCPU, 28 GB RAM, one NVIDIA T4 with 16 GB of GPU memory). The image is built and tested on this size. The larger NCasT4_v3 sizes give more CPU, memory and GPUs. On a size with no GPU Ollama still starts and runs models on the CPU, slowly.

Step 1: Deploy from the Azure Portal

Search Ollama GPU in Marketplace, select the cloudimg publisher and click Create. On the Basics tab choose Standard_NC4as_T4_v3 as the size. NSG rules: TCP 22 (admin), TCP 443 (model API over HTTPS) and TCP 80 (HTTP to HTTPS redirect and health probe), from your client networks.

Step 2: Deploy from the Azure CLI

RG="ollama-gpu-prod"; LOCATION="eastus"; VM_NAME="ollama-gpu-01"
IMAGE_URN="cloudimg1647283583153:ollama-gpu-ubuntu-24-04:default:latest"
SSH_KEY="$(cat ~/.ssh/id_rsa.pub)"
az group create --name "$RG" --location "$LOCATION"
az network vnet create -g "$RG" --name ollama-vnet --address-prefix 10.100.0.0/16 --subnet-name ollama-subnet --subnet-prefix 10.100.1.0/24
az network nsg create -g "$RG" --name ollama-nsg
az network nsg rule create -g "$RG" --nsg-name ollama-nsg --name allow-ssh --priority 100 \
  --source-address-prefixes "<your-mgmt-cidr>" --destination-port-ranges 22 --access Allow --protocol Tcp
az network nsg rule create -g "$RG" --nsg-name ollama-nsg --name allow-https --priority 110 \
  --destination-port-ranges 443 --access Allow --protocol Tcp
az network nsg rule create -g "$RG" --nsg-name ollama-nsg --name allow-http --priority 120 \
  --destination-port-ranges 80 --access Allow --protocol Tcp
# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn "$IMAGE_URN"

az vm create -g "$RG" --name "$VM_NAME" --image "$IMAGE_URN" \
  --size Standard_NC4as_T4_v3 \
  --admin-username azureuser --ssh-key-values "$SSH_KEY" \
  --vnet-name ollama-vnet --subnet ollama-subnet --nsg ollama-nsg --public-ip-sku Standard

First boot takes a few minutes. On its first boot the VM finishes its per-VM setup in the background (generating this VM's own credential and certificate and starting the services). If you connect as soon as the VM shows as running, wait for that setup to complete before continuing:

bash sudo cloud-init status --wait

It prints status: done when the VM is ready. The credential and services described below are only present after that.

Step 3: Connect via SSH and retrieve your credential

The per-VM admin credential is generated on the first boot and stored in a root only file. Connect over SSH and read it:

ssh azureuser@<public-ip>
sudo cat /root/ollama-credentials.txt

The file holds the API URL, the username (admin) and the per-VM password, plus quick start commands. Store the password somewhere safe: it is unique to this VM.

Step 4: Confirm the GPU

The driver is already loaded. nvidia-smi lists the GPU, the driver version and the CUDA version the driver supports:

nvidia-smi

nvidia-smi on a Standard_NC4as_T4_v3 lists one Tesla T4 with 16384 MiB of memory and persistence mode on, NVIDIA driver 580.196.07 and CUDA 13.0

Persistence mode is on (Persistence-M reads On): the image runs nvidia-persistenced with persistence mode enabled and starts Ollama after it, so the GPU stays initialised and Ollama finds it within seconds of each start.

The kernel module is Canonical's prebuilt build for the running Azure kernel, signed with Canonical's kernel module key, so it loads with no DKMS build step:

uname -r
modinfo -F version nvidia
modinfo -F signer nvidia

Step 5: Verify the Ollama and nginx services

Confirm both services are active and that Ollama is bound to loopback only. In the listener output, 127.0.0.1:11434 (Ollama) is loopback only, while nginx listens publicly on :443 and :80:

systemctl status ollama nginx --no-pager
ss -tln | grep -E ':11434|:443|:80 '

ollama, nginx and ollama-firstboot active; ss shows Ollama on 127.0.0.1:11434 only and nginx on :443 and :80; /api/version answers 0.40.19; the nvidia module is 580.196.07, signed by Canonical

Step 6: Check the health endpoint

GET /api/version is served by nginx without authentication (suitable for load balancer and Azure health probes) and returns the Ollama version as JSON:

sudo curl -s --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/api/version; echo
curl -k -o /dev/null -w 'healthz: HTTP %{http_code}\n' https://127.0.0.1/healthz

The self-signed certificate lives at /etc/nginx/tls/ollama.crt, so curl is given it with --cacert. The /etc/nginx/tls directory is readable by root only, so each curl that reads the certificate runs with sudo.

Step 7: Pull a model and confirm anonymous access is rejected

No model ships in the image, so the model list starts empty. Pull one through the authenticated API. llama3.2:3b (about 2 GB) fits the T4's 16 GB of GPU memory with plenty to spare; larger models such as llama3.1:8b or qwen2.5:7b also fit:

PASS=$(sudo grep '^OLLAMA_PASSWORD=' /root/ollama-credentials.txt | cut -d= -f2-)
sudo curl -s -u "admin:$PASS" --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/api/pull \
  -d '{"name":"llama3.2:3b","stream":false}'; echo

It prints {"status":"success"} once the model is on the VM's disk. Now list the models with the credential, and confirm that a request with no credential is refused:

PASS=$(sudo grep '^OLLAMA_PASSWORD=' /root/ollama-credentials.txt | cut -d= -f2-)
sudo curl -s -o /dev/null -w 'anonymous /api/tags -> HTTP %{http_code}\n' --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/api/tags
sudo curl -s -u "admin:$PASS" --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/api/tags | jq -r '.models[].name'
sudo -u ollama OLLAMA_HOST=127.0.0.1:11434 ollama list

The anonymous request returns HTTP 401; the authenticated one lists the model you pulled.

An anonymous request to /api/tags returns HTTP 401; with the admin credential /api/tags lists llama3.2:3b (3.2B, Q4_K_M), and ollama list shows it in the local store

Step 8: Run a completion on the GPU

Send a prompt over the authenticated API, then ask Ollama where the model is loaded:

PASS=$(sudo grep '^OLLAMA_PASSWORD=' /root/ollama-credentials.txt | cut -d= -f2-)
sudo curl -s -u "admin:$PASS" --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/api/generate \
  -d '{"model":"llama3.2:3b","prompt":"In one sentence, why run a language model on a GPU?","stream":false}' \
  | jq '{response, eval_count, tokens_per_second: (.eval_count / (.eval_duration / 1e9) | floor)}'
sudo -u ollama OLLAMA_HOST=127.0.0.1:11434 ollama ps

The PROCESSOR column of ollama ps reads 100% GPU: the whole model is in GPU memory. The API's GET /api/ps reports the same as a size_vram greater than zero.

An authenticated /api/generate request to llama3.2:3b returns a one-sentence answer with its token rate, and ollama ps shows the model loaded 100% on the GPU

nvidia-smi now lists Ollama's runner, /usr/local/lib/ollama/llama-server, and the GPU memory it holds. Ollama unloads an idle model after five minutes; set keep_alive in a request to keep it loaded longer.

Step 9: Use the OpenAI-compatible endpoint from your apps

Point any OpenAI SDK at https://<public-ip>/v1 with basic auth. Example with curl on the VM:

PASS=$(sudo grep '^OLLAMA_PASSWORD=' /root/ollama-credentials.txt | cut -d= -f2-)
sudo curl -s -u "admin:$PASS" --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/v1/chat/completions \
  -d '{"model":"llama3.2:3b","messages":[{"role":"user","content":"Say hello in French"}]}' | jq -r '.choices[0].message.content'

From Python (LangChain, LlamaIndex or the OpenAI SDK), set base_url="https://<public-ip>/v1" and api_key="ollama", and pass the admin / password basic-auth pair and the certificate you trust (Step 10).

Step 10: Your public address and a trusted certificate

First boot puts the VM's address into the TLS certificate, the credentials file and the login banner. Check which address it recorded:

sudo grep '^OLLAMA_URL=' /root/ollama-credentials.txt

If it shows a private address or <your-vm-public-ip> rather than the address your clients use, point the VM at your public IP or DNS name. This updates the credentials file and the banner, makes a new self-signed certificate for that address and restarts nginx:

sudo cloudimg-set-public-address <public-ip>

Copy /etc/nginx/tls/ollama.crt to each client as ollama.crt, then call the API from the client:

curl -u admin:<password> --cacert ollama.crt https://<public-ip>/api/tags

For production, use your own DNS name and a CA-signed certificate:

  • Point a DNS record (for example ollama.example.com) at the VM's public IP and run sudo cloudimg-set-public-address ollama.example.com.

  • Replace /etc/nginx/tls/ollama.crt and /etc/nginx/tls/ollama.key with your CA-signed certificate and key (for example from Let's Encrypt or your internal CA), then run sudo nginx -t && sudo systemctl reload nginx. cloudimg-set-public-address leaves a certificate you installed yourself alone.

  • Clients then call https://ollama.example.com/ with no certificate trust step.

Step 11: Kernel and driver updates

Unattended security upgrades stay on. When Ubuntu publishes a new Azure kernel, the linux-modules-nvidia-580-server-azure package moves with it, so the new kernel arrives with its own signed NVIDIA module. A kernel update takes effect at the next reboot; /var/run/reboot-required exists when one is due. See which driver packages are installed and which kernels have the module:

dpkg-query -W -f='${Package} ${Version}\n' nvidia-headless-no-dkms-580-server nvidia-utils-580-server linux-modules-nvidia-580-server-azure
for k in $(ls /lib/modules | grep -- '-azure$'); do echo "$k: nvidia $(modinfo -k "$k" -F version nvidia)"; done

After a reboot onto a new kernel, nvidia-smi lists the GPU as before.

Step 12: Server components

Component Version / Detail
Runtime Ollama 0.40.19 (pinned at build)
GPU driver NVIDIA 580 server driver 580.196.07 (headless), Canonical-signed prebuilt modules for linux-azure
CUDA runtime Ollama's bundled CUDA 12 and CUDA 13 libraries under /usr/local/lib/ollama
GPU persistence nvidia-persistenced with persistence mode on; ollama.service starts after it
Server binding 127.0.0.1:11434 (loopback only, no auth at this layer)
Front proxy nginx (TLS on :443, htpasswd Basic auth, :80 -> 301 https)
Model store /var/lib/ollama/models on the OS disk (empty at launch)
Credential per-VM admin password, generated on first boot, /root/ollama-credentials.txt (0600)
TLS certificate self-signed, generated per VM on first boot, /etc/nginx/tls/ (root only)
API REST (/api/*) and OpenAI compatible (/v1/*)
Operating system Ubuntu 24.04 LTS with the linux-azure kernel (patched at build)

Step 13: Managing the service

sudo systemctl status ollama --no-pager
sudo journalctl -u ollama --no-pager -n 20
sudo systemctl reload nginx

To restart the runtime after a configuration change: sudo systemctl restart ollama.

Model weights live under /var/lib/ollama/models and persist across service restarts and VM reboots. For a large model library, attach an Azure data disk and mount it at /var/lib/ollama/models (stop ollama, move the data, update the mount, restart).

Troubleshooting:

  • nvidia-smi says it couldn't communicate with the NVIDIA driver: check that the VM is a GPU size, that the module loaded (lsmod | grep nvidia) and that the running kernel (uname -r) has the module (Step 11). After a kernel update, reboot so the new kernel and its module load together.

  • ollama ps shows 100% CPU: the GPU was not found when Ollama started. Check systemctl is-active nvidia-persistenced (it should be active) and that nvidia-smi lists the GPU with Persistence-M On, then sudo systemctl restart ollama.

  • The GPU size is not offered or the deployment fails on quota: request GPU quota for the size's family in that region under Usage + quotas, or choose another region.

Step 14: Security recommendations

  • Restrict the NSG. Allow TCP 443 (and 22 for admin) only from the client networks that need the API. Do not expose the model API to the internet unless you intend to.

  • Rotate the credential. To change the admin password, run sudo htpasswd -B /etc/nginx/.ollama.htpasswd admin, then sudo systemctl reload nginx, and update /root/ollama-credentials.txt to match.

  • Add more users. Grant more accounts with sudo htpasswd -B /etc/nginx/.ollama.htpasswd <username> and reload nginx.

  • Use a trusted certificate (Step 10) for production so clients validate the endpoint without a manual trust step.

  • Keep the OS patched. Unattended security upgrades stay enabled on the running VM; reboot after kernel updates (Step 11).

Step 15: Support and Licensing

Ollama is distributed under the MIT License. The NVIDIA driver is distributed by Ubuntu under NVIDIA's driver licence (/usr/share/doc/nvidia-utils-580-server/copyright), and the CUDA runtime libraries bundled with Ollama under the NVIDIA CUDA Toolkit End User License Agreement (/usr/share/doc/ollama/NVIDIA-CUDA-EULA.txt). No model ships in the image; each model you pull comes under its own licence. This image is packaged by cloudimg and is not affiliated with or endorsed by Ollama or NVIDIA. cloudimg provides the packaging, hardening, per-VM credential and TLS automation, and 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.

Deploy on Azure

Find Ollama GPU on Ubuntu 24.04 on the Azure Marketplace, published by cloudimg. Deploy from the Portal or the Azure CLI as shown above.

Need Help?

Email support@cloudimg.co.uk for deployment help, configuration questions or licensing enquiries.