Spegel (Swedish for "mirror") is an open-source tool that enables peer-to-peer sharing of container images across Kubernetes nodes.
Problem: Normally, each node pulls the necessary image independently from Docker Hub or another registry. If the same image is deployed across 10 nodes, it will be downloaded externally 10 times.
Solution: Spegel runs as a DaemonSet on every node and behaves like a local OCI registry. When a node requests an image:
Instead of each node downloading the same image from an external registry, only the first download is required. Subsequent requests can be served by other nodes in the cluster.
Some of the key benefits include:
For clusters with frequent deployments or many worker nodes, Spegel can significantly reduce network usage while improving deployment speed and overall resilience.
# kind-config.yaml
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
[plugins."io.containerd.grpc.v1.cri".containerd]
discard_unpacked_layers = false
[plugins."io.containerd.metadata.v1.bolt"]
content_sharing_policy = "isolated"
nodes:
- role: control-plane
- role: worker
Important settings:
kind create cluster --config kind-config.yaml
helm upgrade --create-namespace --namespace spegel \
--install spegel oci://ghcr.io/spegel-org/helm-charts/spegel \
--set service.registry.hostPort=30021 \
--set spegel.logLevel=debug
Note: service.registry.hostPort=30021 - In a Kind environment, this ensures that the hostPort matches the nodePort. Without it, the generated containerd mirror configuration contains an incorrect port.
Verify that the pods are running. You should see one pod on each node:
kubectl get pods -n spegel -o wide --watch
Expected output:
NAME READY STATUS NODE
spegel-xxxxx 1/1 Running kind-spegel-demo-control-plane
spegel-yyyyy 1/1 Running kind-spegel-demo-worker
When Spegel is installed, it creates /etc/containerd/certs.d/_default/hosts.toml on every node. This file instructs containerd to send all registry requests to Spegel first.
docker exec kind-worker cat /etc/containerd/certs.d/_default/hosts.toml
Expected output:
[host.'http://192.168.97.3:30021']
capabilities = ['pull', 'resolve']
dial_timeout = '200ms'
Testing Access to Spegel
docker exec kind-worker curl -v http://192.168.97.3:30021/v2/
You should receive HTTP/1.1 200 OK.
First, retrieve the node IP addresses:
kubectl get nodes -o wide
Then update the worker's hosts.toml to point to the control-plane IP (replace 192.168.97.2 with your own control-plane IP):
docker exec kind-worker bash -c 'cat > /etc/containerd/certs.d/_default/hosts.toml << EOF
[host."http://192.168.97.2:30021"]
capabilities = ["pull", "resolve"]
dial_timeout = "5s"
response_header_timeout = "5s"
EOF'
Restart containerd:
docker exec kind-worker systemctl restart containerd
sleep 5
Step 1: Pull the image onto the control-plane
docker exec kind-control-plane crictl pull docker.io/library/nginx:1.27.4
Step 2: Create a tag that exists only on the control-plane node
docker exec kind-control-plane \
ctr -n k8s.io images tag \
docker.io/library/nginx:1.27.4 \
docker.io/library/nginx-spegel-test:latest
Step 3: Verify that the tag does not exist on the worker
docker exec kind-worker crictl img list | grep nginx-spegel-test
# No output should be returned
Step 4: Monitor the control-plane logs
kubectl logs -n spegel \
$(kubectl get pod -n spegel -o jsonpath='{.items[?(@.spec.nodeName=="kind-control-plane")].metadata.name}') \
-c registry -f | jq
Check podCIDR assignments:
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.podCIDR}{"\n"}{end}'
Access the Spegel debug web interface:
kubectl --namespace spegel port-forward spegel-cjq69 9090
# Then open: http://localhost:9090/debug/web/
Step 5: Pull the tagged image onto the worker
docker exec kind-worker crictl pull docker.io/library/nginx-spegel-test:latest
After the pull completes, the Spegel pod running on the control-plane produces the following logs:
{
"path": "/v2/library/nginx-spegel-test/manifests/latest",
"status": 200,
"method": "HEAD",
"ip": "10.244.1.2",
"handler": "manifest",
"registry": "docker.io"
}
{
"path": "/v2/library/nginx-spegel-test/blobs/sha256:16c9c4a8e9...",
"status": 200,
"method": "GET",
"latency": "47.574305ms",
"ip": "10.244.0.1",
"handler": "blob",
"registry": "docker.io"
}
How do we interpret these logs?
These logs show that the image request came from the worker node and that the Spegel instance on the control plane handled it successfully.
Conclusion: The worker node pulled nginx-spegel-test:latest directly from the Spegel instance on the control plane instead of Docker Hub. No request was sent to Docker Hub.
Worker Node
└── crictl pull nginx-spegel-test:latest
└── containerd
└── hosts.toml → Redirect to the Spegel endpoint (192.168.97.2:30021)
└── Spegel (control-plane) → served the manifest and blobs
(No request was sent to Docker Hub)