Skip to main content
Resources

Spegel Peer Cache: Pull Images from Your Own Cluster

Published

Spegel Peer Cache: Pull Images from Your Own Cluster
Note

This resource is part of the Syself Autopilot 1.37 release. For the whole picture, see what's new in 1.37.

When a node is drained during an upgrade, its pods move to other nodes. Those nodes may need to download the same container images again, even if another node in the cluster already has them. That's where a peer cache like Spegel helps. It lets nodes share container image layers directly with each other instead of downloading everything from an external registry.

There's one challenge with running Spegel on Syself Autopilot. Every node uses a sealed, read-only OS, so Spegel cannot modify its own containerd configuration.

Syself Autopilot 1.37 makes this possible with the new containerdRegistryHostsSecretRef variable. Spegel is not part of the Cluster Stack. You install and run it yourself, and the variable lets the platform point containerd on every node at it. We set it up on a test cluster to see how it behaves. Here's how it works and what we found.

Our test cluster 

We created a small Syself Autopilot 1.37 cluster with one control plane and two worker nodes. All three nodes were Hetzner Cloud cpx32 servers in the same location, and we installed Spegel 0.8.2. To test different image sizes and registries, we pulled four public images:

ImageRegistryCompressed size
python:3.13-slimpublic.ecr.aws43 MB
node:22public.ecr.aws409 MB
home-assistant:stableghcr.io674 MB
jupyter/pytorch-notebookquay.io1.55 GB

Before each test, we removed the images and their layers from both workers. This ensured that every pull started without a local copy.

Configure Spegel as a peer cache 

The setup has two parts. First, configure containerd to send image requests to Spegel. Then install Spegel with its own containerd configuration disabled.

1. Create the containerd hosts file 

Start by creating a hosts.toml file that points every registry to Spegel's port on the local node:

hosts.tomltoml
				[host."http://127.0.0.1:30020"]
capabilities = ["pull", "resolve"]
			

By default, the platform places this file in the _default folder on each node. This means it applies to every registry without its own configuration. The address points to Spegel's NodePort, which listens on port 30020 on every node.

2. Create a Secret 

Create a Secret from the hosts file in the cluster's namespace on the management cluster:

				$ kubectl -n <namespace> create secret generic containerd-registry-hosts \
  --from-file=hosts.toml=hosts.toml
			

3. Enable the configuration on your Cluster 

Add the containerdRegistryHostsSecretRef variable to your Cluster:

yaml
				spec:
  topology:
    variables:
      - name: containerdRegistryHostsSecretRef
        value:
          enabled: true
          name: containerd-registry-hosts
			

Changing this variable replaces every node, including control-plane nodes. Once the rollout finished, every node had the file at /etc/containerd/certs.d/_default/hosts.toml. The node image keeps its own entry for registry.k8s.io.

4. Install Spegel 

Now install Spegel with its containerd configuration disabled:

				$ helm upgrade --install spegel oci://ghcr.io/spegel-org/helm-charts/spegel \
  --namespace spegel --create-namespace \
  --set spegel.containerdMirrorAdd=false
			

This setting is important. By default, Spegel's init container tries to write to the node's containerd configuration. Because the OS is read-only, it fails with:

				mkdir /etc/containerd/certs.d/_backup: read-only file system
			

Setting spegel.containerdMirrorAdd=false prevents this. The DaemonSet can then start on every node, and containerd reaches Spegel through a NodePort.

Spegel mounts the containerd socket and image store from the host. If you enforce Pod Security Standards, keep the spegel namespace at the privileged level.

You can check the services with:

				$ kubectl -n spegel get svc
NAME               TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
spegel             ClusterIP   10.129.244.118   <none>        9090/TCP         9s
spegel-bootstrap   ClusterIP   None             <none>        <none>           9s
spegel-registry    NodePort    10.136.219.155   <none>        5000:30020/TCP   9s
			

The important service is spegel-registry. It exposes port 30020 on every node, matching the address in our hosts file.

How an image pull works 

Once everything is running, here's what happens when a pod requests ghcr.io/acme/app:v1:

  1. containerd looks for a certs.d/ghcr.io/ directory on the node. If it doesn't find one, it uses _default/hosts.toml.
  2. It contacts Spegel at http://127.0.0.1:30020 to resolve and pull the image. Spegel checks whether another node already has the image layers.
  3. If a node has them, Spegel streams the layers directly from that node. They don't need to come from the internet.
  4. If no node has the layers, or Spegel isn't running yet, containerd pulls the image from ghcr.io as usual. The node can then share the image with other nodes.

Our guide Use a registry mirror or peer cache explains the setup in more detail, including network policies and Pod Security.

Stay up to date

Subscribe to The Syselfer, our newsletter, or add the RSS feed to your reader.

RSS

What we found 

Where do the image layers come from? 

When another node already had an image, the pulling node retrieved its layers from inside the cluster. We counted the bytes transferred through each node's network interfaces. Traffic from other nodes arrives through the cluster's overlay network, while traffic from the internet does not. In 10 of 12 pulls, every layer came from another node. In the remaining 2 pulls, some layers still came from the registry.

What happens when a node is drained? 

We created a Deployment with three replicas of node:22 on one worker and drained that node. The other worker didn't have a copy of the image. We repeated the test with pytorch-notebook. In both cases, most of the image came from the drained node, but the pods didn't become ready any sooner than without Spegel.

Can Spegel serve images when the registry is down? 

We tested this by placing an image in a registry that only one worker could reach. After pulling the image on that worker, we deleted the registry and tried pulling the same image on the other worker. The pull succeeded, and every layer came from the first worker. We also tried pulling an image that no node had downloaded before. That pull failed with a NotFound error.

Spegel can only serve images that at least one node already has.

What happens when a new node joins? 

We scaled the worker pool from two to three nodes. The new node received the hosts file during its first boot, and its Spegel pod became ready shortly after the node joined. We then pulled node:22 and pytorch-notebook. Both images came from other nodes, with no traffic from the internet.

What did we learn? 

Our tests showed two practical benefits of Spegel:

  • Less external registry traffic. When another node already has an image, the pulling node gets its layers from inside the cluster without using internet traffic for those layers.
  • Pull images when the registry is unavailable. Spegel can serve images that are already cached on another node.

Spegel changes where image layers come from, not how long containerd takes to unpack them. For larger images, unpacking takes most of the pull time, so don't expect pods to start noticeably faster.

Important things to consider 

Changing the variable replaces every node 

The hosts file is part of the node's boot configuration. Enabling or disabling the variable replaces all nodes, including control-plane nodes. Editing the Secret alone doesn't update running nodes. New nodes receive the Secret's current content when they're created. This means nodes can end up with different hosts files if you edit the Secret without replacing existing nodes. To roll out an updated hosts file, create a Secret with a new name and update the variable's name field.

The Secret must exist before you enable the variable 

The platform reads the Secret whenever it creates a node. If the Secret doesn't exist, new nodes cannot finish provisioning. Create the Secret before enabling the variable.

The NodePort is publicly accessible 

Spegel's cache listens on port 30020 on every node. Without a network policy restricting access, anyone who can reach a node on that port can pull cached images, including private images. See Use a registry mirror or peer cache for details.

Private images are shared across the cluster 

Spegel doesn't check image pull secrets. Once a node pulls a private image, a pod on any node can retrieve it from the cache without a pull secret. This also applies when using imagePullPolicy: Always. If teams in your cluster must not be able to access each other's images, don't use a peer cache.

Ready to Build? Start a Trial

Start with a trial, and our step-by-step guides will walk you through your first cluster deployment in minutes.

Tags

Product UpdatesKubernetesInfrastructure