Onam
AI Security

How to secure Ollama on Kubernetes

By Anup Yadav, Founder & CEO•November 28, 2026•9 min read

Would rather we looked for you? We run a free one-time audit scan of one cloud account and go through the results with you. No charge, no commitment.

Free audit scan

Running Ollama on Kubernetes is easy, and that is how it gets exposed. The Ollama API has no login. Inside a cluster, any pod that can reach the Service can use it. This guide shows how to find every Ollama you run, test who can reach it, and close it off with commands you can copy today.

Every Ollama behaviour below is quoted from Ollama's own documentation or repository, read on 28 November 2026. Run the probe commands only against clusters you own or are authorised to test.

What an attacker sees (a hypothetical)

This is a thought experiment, not an incident. Someone has a shell in one pod of your cluster, say a web app with an old dependency. They do not know you run Ollama, and they do not need to.

  1. They try the obvious name and port: curl http://ollama:11434/api/version. A version number comes back.
  2. GET /api/tags lists every model on the server. GET /api/ps shows which ones are loaded in GPU memory right now.
  3. POST /api/generate runs prompts on your GPUs. POST /api/pull downloads models from the Ollama library onto your volume. DELETE /api/delete removes "a model and its data", including the one your team fine-tuned.

None of this is an exploit. Every call is in the Ollama API reference, working as designed. The question is only who can reach it.

Why Ollama is open inside a cluster

Three documented defaults line up:

  • On a laptop, Ollama is local only. "Ollama binds 127.0.0.1 port 11434 by default. Change the bind address with the OLLAMA_HOST environment variable" (Ollama FAQ).
  • In a container, it listens everywhere. The official image sets ENV OLLAMA_HOST=0.0.0.0:11434 and EXPOSE 11434 (Ollama Dockerfile). That is what lets a Kubernetes Service reach the pod at all.
  • There is no login on the API. "The local API at http://localhost:11434 does not require authentication." API keys exist only for Ollama's hosted cloud API (Ollama authentication docs).

Kubernetes adds the fourth piece: "By default, a pod is non-isolated for ingress; all inbound connections are allowed" (Kubernetes NetworkPolicy docs). So with no NetworkPolicy, every pod in every namespace can call your Ollama. A NodePort, LoadBalancer or Ingress widens that to your network or the internet.

The internet-facing version of this is measurable. On 1 September 2025, Cisco Talos reported finding 1,139 exposed Ollama instances through Shodan, 214 of them "actively hosting and responding to requests with live models" (Cisco blog). The in-cluster version does not show up on Shodan, which is why you have to look for it yourself.

Find every Ollama in your cluster

Read-only commands. They need only get and list permissions.

# 1. Every pod running an Ollama image, in every namespace
kubectl get pods -A -o custom-columns='NAMESPACE:.metadata.namespace,POD:.metadata.name,IMAGE:.spec.containers[*].image' | grep -i ollama

# 2. Every Service that targets port 11434, and its type
kubectl get svc -A -o custom-columns='NAMESPACE:.metadata.namespace,NAME:.metadata.name,TYPE:.spec.type,PORT:.spec.ports[*].port,TARGET:.spec.ports[*].targetPort' | grep -E '11434|NAMESPACE'

# 3. Anything reachable from outside the cluster
kubectl get svc -A | grep -E 'LoadBalancer|NodePort'
kubectl get ingress -A

# 4. Where OLLAMA_HOST is set explicitly
kubectl get pods -A -o yaml | grep -n -A1 'OLLAMA_HOST'

# 5. Is there any NetworkPolicy in the namespace? (replace ai with yours)
kubectl get networkpolicy -n ai

Step 1 matters because a Service does not have to use port 11434. A Service on port 80 with target port 11434 is still Ollama. If step 5 returns nothing, every pod in the cluster can reach it.

Test it the way an attacker would

Start a throwaway pod in a different namespace and call the API. If it answers, so would any compromised pod in that namespace.

kubectl run np-probe -n default --rm -it --restart=Never --image=curlimages/curl -- curl -s -m 5 http://ollama.ai.svc.cluster.local:11434/api/tags

Replace ollama.ai with your Service name and namespace. A JSON list of models means the door is open. A timeout after you apply the policies below means it is closed. For a LoadBalancer or Ingress, run the same curl from a machine outside your network.

How exposed is yours?

How Ollama is publishedWho can call the APIWhat to do
ClusterIP, no NetworkPolicyEvery pod in the clusterAdd default-deny plus an allow rule for named clients
ClusterIP with NetworkPolicy, enforcedOnly the pods you allowedRe-test after every policy or label change
NodePortAnyone who can reach a node's IPChange to ClusterIP
LoadBalancerAnyone who can reach the load balancer, possibly the internetChange to ClusterIP, or put an authenticating proxy in front
Ingress with no authAnyone who can reach the Ingress hostAdd authentication at the Ingress or proxy
kubectl port-forward onlyWhoever has kubectl access to the namespaceFine for testing; that access is governed by RBAC

Fix it in four steps

Lock down OllamaStep 1 of 4

11. Keep the Service internal

Use type: ClusterIP and no Ingress. If someone outside the cluster needs Ollama, route them through step 3 rather than a raw LoadBalancer.

22. Deny by default, then allow named clients

Apply both policies in Ollama's namespace. The first blocks all inbound traffic to every pod in the namespace. The second lets only pods labelled ollama-client: "true" in the chat-app namespace reach port 11434. Kubernetes sets the kubernetes.io/metadata.name label on every namespace, so you can target one by name.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-ingress
  namespace: ai
spec:
  podSelector: {}
  policyTypes:
  - Ingress
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: ollama-allow-clients
  namespace: ai
spec:
  podSelector:
    matchLabels:
      app: ollama
  policyTypes:
  - Ingress
  ingress:
  - from:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: chat-app
      podSelector:
        matchLabels:
          ollama-client: "true"
    ports:
    - protocol: TCP
      port: 11434

Check that app: ollama matches your pod labels with kubectl get pods -n ai --show-labels.

33. Put a login in front of anything wider

Ollama has no API key on its local API, so authentication has to live in front of it. Ollama's FAQ shows it running behind a reverse proxy such as Nginx. Use your Ingress controller's authentication or an authenticating proxy, and keep Ollama itself on ClusterIP. A tighter variant: run the proxy as a sidecar and set OLLAMA_HOST=127.0.0.1:11434 on the Ollama container, so the proxy is the only thing listening on the pod IP; point the Service and any health probes at the proxy's port.

44. Re-run the probe

Run the np-probe command again from a namespace you did not allow. It should time out. Run it from an allowed pod and it should answer.

What a NetworkPolicy fixes

  • Stops pods you did not allow from reaching port 11434
  • Turns "every pod in the cluster" into a list you chose
  • Works without changing Ollama or its image

What it does not fix

  • It adds no login: any allowed pod can still pull, run and delete models
  • "Creating a NetworkPolicy resource without a controller that implements it will have no effect", so confirm your network plugin enforces it
  • Behaviour for traffic arriving through load balancers and ingress, where source IPs are rewritten, depends on your plugin and cloud

The last two points are from the Kubernetes NetworkPolicy docs. They are why step 4 is a real test from a real pod, not a read of the YAML.

Ollama on Kubernetes: the two-minute check
Image
Found every pod running an Ollama image, not only Services named "ollama"
Service
ClusterIP only; no NodePort, LoadBalancer or open Ingress
Policy
Default-deny ingress in the namespace, plus one allow rule for named clients on 11434
Enforcement
Your network plugin enforces NetworkPolicy, proven by the probe pod timing out
Wider access
Anything from outside the namespace goes through an authenticating proxy
Re-test
The probe runs again after every policy, label or chart change

Where Onam fits (that is us)

Onam's AI security finds self-hosted AI on Kubernetes, Ollama included, and checks whether it is exposed. It connects through a read-only ServiceAccount bound to a get/list/watch ClusterRole (Kubernetes connection guide). Self-hosted model servers appear in the same AI inventory as your cloud AI services on AWS, Azure and Google Cloud, next to an AI bill of materials built from SBOMs.

  • The honest limit: today this is inventory and exposure only. The configuration rules for self-hosted AI on Kubernetes are written but not switched on, so Onam tells you what runs and whether it is reachable, not yet whether each server is configured safely.

Our prices are public: $20 per unit a month for Complete, which includes data security; $14 per unit a month for Posture; and $39 per active developer a month for code security, with a 25-unit minimum. There is no time-limited trial. Instead there is a free plan of up to 25 units with API-based scanning only, and a free one-time audit scan of one cloud account. Finding self-hosted AI on Kubernetes needs a cluster connection, which is on paid plans.

Frequently asked questions

Does Ollama have authentication?

Not on the local API. Ollama's documentation says the local API at port 11434 "does not require authentication". API keys apply only to Ollama's hosted cloud API at ollama.com. To require a login for a self-hosted server, put an authenticating proxy in front of it.

Is it safe to set OLLAMA_HOST to 0.0.0.0?

It makes Ollama listen on every network interface, which a container needs so a Kubernetes Service can reach it. The official Docker image already sets OLLAMA_HOST=0.0.0.0:11434. It is safe only when something else limits who can connect: a ClusterIP Service, an enforced NetworkPolicy and, for wider access, an authenticating proxy.

How do I check if Ollama port 11434 is exposed?

List Services that target 11434 with kubectl get svc -A, look for NodePort, LoadBalancer and Ingress entries, then call /api/tags from a throwaway pod in another namespace. If it returns your model list, it is reachable from there.

Does a Kubernetes NetworkPolicy secure Ollama?

It limits who can reach Ollama, which is most of the fix. It does not add a login, and it has no effect unless your network plugin enforces NetworkPolicy. Combine it with a ClusterIP Service and test it from a pod you did not allow.

Can I add an API key to self-hosted Ollama?

Not in Ollama itself. Put a reverse proxy or your Ingress controller's authentication in front, and keep the Ollama Service internal so the proxy cannot be bypassed.

What can someone do with an exposed Ollama API?

Everything the API offers: list models, see which are loaded, run prompts on your hardware, pull new models onto your storage, create models and delete existing ones.

Read next

Try it on your own cloud

Start free. The free plan covers up to 25 units of cloud security, with API-based scanning only: posture (CSPM), identity and permissions (CIEM), data stores found through cloud APIs (DSPM checks, no content classification) and AI-SPM. Posture scanning connects through read-only cloud roles, the free plan deploys no agent or scanner, and no card is needed. Register, and the team emails you the login.

Start free · Book a demo

See this on your own cloud, free

The free plan covers up to 25 units of cloud security with read-only cloud API scanning. It deploys no agent or scanner and needs no card. Register, and the team emails you the login.