Skip to content

Package cache and hosts without internet ​

Hosts download packages through the hub, and each .deb goes to the internet once for all hosts. It is turned on in "About" → "Package cache" with "Use the hub package cache" (off by default). The hub needs no public address, and the hosts get no new open ports.

How it works ​

  • For every host with "packages through the hub cache" (a checkbox in the host form, on by default) the hub keeps a separate SSH session with a reverse port forward: on the host 127.0.0.1:3142 (NKT_HUB_APTCACHE_PORT) leads to the hub's caching proxy. The session reconnects by itself; an icon in the "Channel" column shows whether the forward is up.
  • The host has /etc/apt/apt.conf.d/99nkt-hub-proxy and /usr/local/bin/nkt-apt-proxy — the standard Acquire::http::Proxy-Auto-Detect and Acquire::https::Proxy-Auto-Detect: the script answers with the proxy address if the port is open and DIRECT if the hub isn't connected — apt then works as usual. Every scheme needs its own line: apt asks for them separately (measured on apt 3.0.3), and with only the http line an https mirror — deb https://…, or the base behind mirror+file — never reached the script and downloaded past the cache, silently, with no error. The files are put there when nkt is installed from the hub, and on an already installed host — right when the checkbox is turned on (root or passwordless sudo is needed).
  • A machine the hub creates gets the same checkbox from the host it runs on: the cache is the same, and the hub keeps the reverse-forward session to the machine itself (through its host when there is no direct path), so the virtual network of the machine is not opened to anyone. It is turned off and back on in the machine's own form; for a cluster node whose outbound TCP is silent this is enough — apt goes to the hub instead of the internet.
  • Only immutable content is cached — pool/… and by-hash/…; indexes (dists/…) pass through; https repositories are tunneled as is — the proxy doesn't look inside TLS and .deb files there don't settle, but they do travel over the same channel.
  • The "localhost" row doesn't use the cache.
  • The cache could not fetch a package — say, the host installs from a hosting provider's internal mirror the hub cannot see, and the cache answers 502: any package installation nkt does (Traffic Fly, nkt-edge, host preparation, UPS, profiles, install buttons in the UI) is retried directly, bypassing the cache, with a line about it in the log.

"About" → "Package cache": size, file count, hits and misses, traffic, how many hosts are on the forward, a limit in gigabytes (NKT_HUB_APTCACHE_MAX_GB, 20 by default; 0 — no limit; the value set in the UI wins) and clearing. When full, the least recently requested content is evicted.

Files by URL ​

The same port does more than apt. Everything a host needs from the internet for clusters and machines goes through the hub when the port is open and settles in its cache: a host without internet access gets it from the hub, a host with access doesn't download per node what the hub has already seen. The host checks that the port answers as the nkt cache (/nkt/ping): someone else's proxy on the same port is not taken for it. Port closed — everything goes direct.

GET http://127.0.0.1:3142/nkt/artifact?url=… — the hub downloads the URL itself and serves it from the cache. That's how the k3s installer and binary with airgap images (k3s is installed with INSTALL_K3S_SKIP_DOWNLOAD), the Cilium CLI, the pkgs.k8s.io repository key, the Flannel manifest, cloud machine images, the helm archive and the Longhorn chart tarball are fetched. URLs with a version in the path and .deb files are kept indefinitely, the rest (get.k3s.io, …/latest/…, the "current" Ubuntu image) is re-downloaded when older than 6 hours; if the source is unavailable, the copy is served. Machine images in the “Images” section go through the cache too while its port is open: the catalogue carries the label “downloads go through the hub cache”, and next to the download button there is “download bypassing the hub” for the case when a guaranteed fresh copy from the mirror is needed instead of the cached one.

An add-on chart is installed in two steps: first the chart tarball arrives through /nkt/artifact and lands on the control plane at /var/lib/nkt/addons/longhorn-<version>.tgz (the step is optional — if it does not arrive, the install still takes the chart from the repository), then helm installs the downloaded file. If the chart does come from the repository, helm repo add and helm repo update run with HTTPS_PROXY set to the cache address — a repository index changes, so it is not cached, but it reaches the node through the hub. The proxy is set on those commands only: the helm install step talks to the cluster's API server, and a shared HTTPS_PROXY would route that request through the hub.

Registry mirror ​

/v2/… at the same address — a pull-through cache of container images. containerd on a cluster node is configured to fetch docker.io, quay.io, registry.k8s.io, ghcr.io and gcr.io through the mirror (k3s — /etc/rancher/k3s/registries.yaml, kubeadm — /etc/containerd/certs.d/<registry>/hosts.toml).

  • Layers and manifests by digest are kept indefinitely, "tag → digest" — 5 minutes; if the source is unavailable, the previous value is used.
  • The hub reaches the sources anonymously (Bearer per the WWW-Authenticate challenge); private images don't go through the mirror.
  • .deb files from https repositories (pkgs.k8s.io) are still tunneled without caching.

A cluster dry run checks URLs through the hub cache when there is one, and with "prepare as well" the hub puts everything the nodes will fetch into the cache in advance.