Skip to content
Architecture by scenario

Architecture by scenario

Each scenario below shows the cluster boundary, the operator, the agent it runs and the objects it creates, and the peer on the far side of the tailnet. The diagrams render on the website; in a plain Markdown viewer they appear as Mermaid source. Model and how it works explains the kinds and the reconcilers in prose; this page shows the resulting shape.

Conventions: corp is the Tailnet, tailnet-system the operator namespace, billing-dev and shop-dev tenant namespaces.

Egress: a namespace reaches a host at the site

    flowchart LR
  subgraph cluster["Kubernetes cluster"]
    subgraph ns["namespace billing-dev"]
      app["app pod"]
    end
    subgraph ops["namespace tailnet-system"]
      op["tailnet-operator"]
      svc["Service db-1\n(ClusterIP :1521)"]
      agent["agent pod billing-dev\n(userspace tsnet, AGENT_MODE=egress)"]
      np["NetworkPolicy\nconsumerNamespaces only"]
    end
  end
  hs["Headscale"]
  router["subnet router\n(tag:fabric)"]
  db["db-1 10.0.5.20:1521"]
  op -- "pre-auth key, policy" --> hs
  op -. "creates" .-> svc & agent & np
  app -- "db-1.tailnet-system.svc:1521" --> svc --> agent
  agent == "WireGuard" ==> router --> db
  

TailnetEgress billing-dev yields one agent Deployment, one Service per target and a NetworkPolicy that admits only the listed consumer namespaces. The agent registers as egress-billing-dev with tag:egress-billing-dev, accepts the site routes and Dials the target over the tailnet; the operator derives the tag owner and the grant from the CR.

Ingress: tailnet peers reach a cluster Service

    flowchart RL
  subgraph cluster["Kubernetes cluster"]
    subgraph ns["namespace shop-dev"]
      agent["agent pod ingress-shop\n(AGENT_MODE=ingress)"]
      np["NetworkPolicy\nhealth port from operator"]
      backend["Service shop-db-rw :5432"]
    end
    subgraph ops["namespace tailnet-system"]
      op["tailnet-operator"]
      hosts["ConfigMap tailnet-dns-hosts"]
    end
  end
  hs["Headscale"]
  peer["peer in group:shop"]
  op -- "pre-auth key, policy" --> hs
  op -. "creates" .-> agent & np & hosts
  peer -- "shop-shop-dev.prod-1.tailnet.example.internal:5432" --> agent --> backend
  

TailnetIngress shop lives in the tenant namespace. Its agent listens on the tailnet as one node (ingress-shop, tag:ingress-shop) and forwards to the backend Service; allowFrom becomes the grant, and the DNS name is written into the hosts ConfigMap for the cluster’s CoreDNS.

Ingress mode: http: TLS terminated on the agent

    flowchart RL
  subgraph cluster["Kubernetes cluster"]
    subgraph ns["namespace shop-dev"]
      agent["agent pod ingress-shop\nTLS listener, SNI routing"]
      cert["cert-manager Certificate\n→ Secret (projected)"]
      web["Service shop-web :8080"]
    end
    op["tailnet-operator"]
  end
  issuer["cert-manager issuer"]
  peer["browser on the tailnet"]
  op -. "creates" .-> agent & cert
  cert -- "issues" --> issuer
  peer -- "https://shop-shop-dev.prod-1.tailnet.example.internal" --> agent -- "HTTP, or verified HTTPS\nwith backend.tls" --> web
  

Each mode: http expose is a virtual host: the agent terminates TLS with the certificate the operator requested from cert-manager (or a Secret you supply), routes by SNI and Host, and forwards HTTP/1.1 or HTTP/2 to the backend — plain, or HTTPS verified against backend.tls.

Gateway: subnet router and split-DNS as a CR

    flowchart LR
  subgraph cluster["Kubernetes cluster"]
    subgraph ops["namespace tailnet-system"]
      op["tailnet-operator"]
      sts["StatefulSet corp-gateway\n(containers tailscale + coredns)"]
      lb["Service corp-gateway\n(LoadBalancer, pool IP)"]
      dns["Service dns.serviceName\n(ClusterIP :53)"]
      state["Secret state\n(persistent identity)"]
      receipts["ConfigMaps -fresh, -auth-receipt\n(immutable receipts)"]
    end
    coredns["cluster CoreDNS"]
  end
  hs["Headscale"]
  peer["tailnet peer"]
  op -- "mints bootstrap key,\napproves routes" --> hs
  op -. "creates once" .-> sts & lb & dns & state & receipts
  peer -- "10.0.0.0/8 via advertised route" --> lb --> sts
  coredns -- "forward zone" --> dns
  

TailnetGateway is the one persistent identity: created exactly once, pinned by receipts, never restarted or adopted by the operator. Route changes flow into the StatefulSet template, the hosts file into the CoreDNS zone. Deleting the CR removes nothing unless deletionPolicy: Delete.

Policy and keys: what the operator says to Headscale

    sequenceDiagram
  participant CR as Tailnet / Egress / Ingress / Site CRs
  participant Op as tailnet-operator
  participant HS as Headscale API
  Op->>HS: create working API key from the bootstrap key
  Note over Op,HS: rotated at half-life, new key verified before the old one expires
  CR->>Op: tags, consumers, allowFrom, site networks
  Op->>Op: render base policy + tagOwners, /32 approvals, grants + merge reviewed spoke fragments
  Op->>HS: validate and set policy (mode Apply)
  Op->>HS: create reusable pre-auth key per agent (ephemeral for egress, persistent for ingress)
  Op->>HS: list nodes, classify routes (NotAdvertised / NotApproved / NoGrant)
  Op->>HS: approve routes missed by autoApprovers
  

Everything the operator writes to Headscale is derived from CRs and visible beforehand: the rendered policy lands in a ConfigMap, DryRun shows it without writing. A second cluster that shares the Headscale cannot write; in mode: Export it renders only its own entries into a fragment ConfigMap, which the single Apply writer merges after review — see Second cluster .

Console: a web view, with optional grant management

    flowchart LR
  peer[Tailnet peer, browser] -->|HTTPS| ing[TailnetIngress console<br/>agent terminates TLS]
  ing -->|HTTP :8080| con[tailnet-console<br/>Deployment, chart value]
  con -->|get / list / watch| api[Kubernetes API<br/>Tailnets, TailnetIngresses,<br/>TailnetSites, TailnetGrants]
  con -.->|accessManagement: create / patch TailnetGrants<br/>and TailnetAccessRequests,<br/>write the audit head ConfigMap| api
  prom[Prometheus] -.->|accessManagement: HTTP :8081 /metrics| con
  con -.->|accessManagement: append + fsync| vol[(PVC audit.jsonl)]
  con -->|HTTP :8082, projected token| op[tailnet-operator<br/>console API]
  op -->|TokenReview| api
  op -->|working key| hs[Headscale API<br/>users, nodes, policy]
  peer -.->|sign-in, PKCE| idp[OIDC identity provider]
  con -.->|code exchange, keys, UserInfo| idp
  

The chart renders the console with console.enabled; it is not created by a CR. It reads four kinds through its own ClusterRole and by default writes nothing, neither to Kubernetes nor to Headscale. With console.accessManagement it creates and patches TailnetGrants, which the operator renders like any other grant: the console never talks to Headscale. Access requests are TailnetAccessRequests, which only the console reads; the operator ignores them, and an approved request becomes a TailnetGrant. Each change is appended to a hash-chained log on its own volume first, and the chain’s head is written to a ConfigMap; reads and writes of grants, requests and of that ConfigMap go straight to the API server, not through the cache. It has no Headscale key: users, tagged nodes and the live policy come from the operator’s console API, which every operator replica serves and which admits only the console’s ServiceAccount. The server renders the overview’s map as SVG; the browser fetches the page again every 10 seconds, so no update channel exists beyond plain GETs. The admin publishes the console with a TailnetIngress in mode: http (Console ).

What the operator creates

CRKubernetes objects (owned, garbage-collected with the CR)Headscale sideOn delete
Tailnet corpSecret corp-apikey (working key, expiry in annotations); with dns: ConfigMap spec.dns.hostsConfigMap; with policy: ConfigMap <base>-renderedAPI keys created and expired on rotation; policy written in ApplySecret and ConfigMaps go; the live policy and keys stay as they are
TailnetEgress billing-devDeployment billing-dev, ConfigMap billing-dev-targets, Secret billing-dev-authkey, one Service per target (named after the target), NetworkPolicy billing-devPre-auth key (reusable, ephemeral, rotated); node egress-billing-dev; stale offline duplicates removedObjects are garbage-collected; the ephemeral node ages out
TailnetIngress shopDeployment ingress-shop, ConfigMap shop-targets, Secret shop-authkey, NetworkPolicy ingress-shop, ServiceAccount/Role/RoleBinding ingress-shop, state Secret ingress-shop-state-<hash>; mode: http with an issuer: cert-manager Certificate and its TLS SecretPre-auth key (reusable, non-ephemeral, rotated); persistent node ingress-shop; DNS name in the hosts fileObjects are garbage-collected; the operator deletes the node (best effort, before the finalizer is dropped)
TailnetGateway corp-gatewayStatefulSet, headless Service, LoadBalancer Service, DNS ClusterIP Service, CoreDNS ConfigMap, ServiceAccount, Role, RoleBinding, PDB; state Secret and auth Secret; receipt ConfigMaps — none with an owner referenceNon-ephemeral bootstrap key; persistent node; approved routesRetain (default): nothing; Delete: fail-closed teardown of what this Gateway provably created
TailnetSitenoneautoApprovers and approvals for the declared networkRendered policy loses the entries
TailnetGrantnoneOne grant in the rendered policy while the target is valid and expiresAt has not passedRendered policy loses the grant at the next policy reconcile

Names and labels follow the CR name; selectors are per CR, so two CRs never share a pod. For the field-level view see the CRD reference , for the gateway’s exact contract the TailnetGateway reference .

Source: docs/explanation/architecture.md at v0.28.2 — found a mistake? Tell us.