Use the `containerdRegistryHostsSecretRef` cluster variable to configure registry mirrors or peer caches on Syself nodes. The variable references a Secret in the management cluster containing a containerd registry hosts file (`hosts.toml`). Syself writes this file to every node when it is created. ## How the configuration is applied The variable writes the Secret's `hosts.toml` to `/etc/containerd/certs.d//hosts.toml` on each new node. Containerd reads the file when it pulls an image. Keep these behaviors in mind: - **The file is read-only on the node.** Neither a process on the node nor a privileged pod can modify it. If a registry agent normally writes its own containerd configuration, disable that feature and provide the configuration through this variable instead. - **Changes replace every node.** Nodes read the file when they are created. Enabling the variable or changing its configuration triggers a rollout of all nodes, including control planes. - **One file per cluster.** You can configure one registry, or use `_default` to apply the file to registries without their own configuration. | Field | Default | Description | | ---------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | `enabled` | `false` | Set to `true` to write the file to every node | | `name` | `containerd-registry-hosts` | Name of the Secret | | `key` | `hosts.toml` | Secret key containing the file | | `registry` | `_default` | Registry the file applies to, such as `ghcr.io` or `registry.example.com:5000`. `_default` applies to registries without their own entry | The node image already has a separate configuration for `registry.k8s.io`. Using `_default` does not override that entry. ## Configure the registry hosts file Containerd tries the configured hosts in order. If a host cannot serve the image, containerd can fall back to the registry itself. For example, to use a pull-through mirror for a registry, create a `hosts.toml` like this: ```toml [host."https://mirror.example.com"] capabilities = ["pull", "resolve"] ``` - `pull` allows containerd to fetch image content from the mirror. - `resolve` allows containerd to resolve image tags to digests. See the [containerd registry host configuration](https://github.com/containerd/containerd/blob/main/docs/hosts.md) for the available options. The variable only writes `hosts.toml`. It cannot install a CA certificate alongside the file on the node. Use a mirror with a certificate issued by a public certificate authority. ## Enable the configuration Create the Secret Create the Secret in the cluster's namespace on the [management cluster](/docs/hetzner/apalla/platform/setup/access-the-management-cluster): ```console $ kubectl -n create secret generic containerd-registry-hosts \ --from-file=hosts.toml=hosts.toml ``` > [!WARNING] > Create the Secret before enabling the variable. New nodes need the Secret to finish provisioning. If it is missing, those nodes cannot complete provisioning. Set the cluster variable Set `containerdRegistryHostsSecretRef` on the `Cluster` object: ```yaml spec: topology: variables: - name: containerdRegistryHostsSecretRef value: enabled: true name: containerd-registry-hosts # Secret name key: hosts.toml # key inside the Secret registry: _default # or a specific registry, such as ghcr.io ``` The `name`, `key`, and `registry` fields use the defaults shown above. If you keep those values, you only need to set `enabled: true`. Use the Cluster Configurator to fill in your cluster's fields and export a ready-to-apply manifest. Wait for the rollout Syself replaces the nodes one at a time. Watch the Machines until the rollout is complete: ```console $ kubectl -n get machines -w ``` ## Update or remove the configuration Editing the Secret does not update running nodes. Each node keeps the file it received when it was created. To apply an updated file: 1. Create a new Secret with a different name, for example `containerd-registry-hosts-v2`. 2. Update the variable's `name` field to reference the new Secret. 3. Wait for the node rollout to complete. 4. Delete the old Secret. To remove the configuration, set `enabled: false`. This also triggers a rollout of all nodes. ## Share images between nodes with Spegel [Spegel](https://spegel.dev) is an in-cluster peer cache. It runs on every node and serves image layers that other nodes have already pulled. This lets a node retrieve cached layers from another node instead of downloading them from the original registry. To use Spegel, configure containerd to contact the local Spegel instance first, then install Spegel on the cluster. Configure containerd to use Spegel Spegel serves its registry on port `30020` of each node. Create a `hosts.toml` that points containerd to the local instance: ```toml [host."http://127.0.0.1:30020"] capabilities = ["pull", "resolve"] ``` Create the Secret and enable `containerdRegistryHostsSecretRef` as described in [Enable the configuration](#enable-the-configuration). Set `registry: _default` so the cache is used for registries without their own configuration. If Spegel is not running or does not have the requested image, containerd falls back to the original registry. Install Spegel Install Spegel and disable its automatic containerd mirror configuration. Syself manages the containerd hosts file, and the node's `/etc` directory is read-only. ```console $ helm upgrade --install spegel oci://ghcr.io/spegel-org/helm-charts/spegel \ --namespace spegel --create-namespace \ --set spegel.containerdMirrorAdd=false ``` Spegel runs as a DaemonSet and mounts the containerd socket and image store from the host. If you [enforce Pod Security Standards](/docs/hetzner/apalla/security/enforce-pod-security-standards), set the `spegel` namespace to the `privileged` level. Restrict access to the cache Spegel publishes its registry through a `NodePort` Service on port `30020`. Without a load balancer in front of it, this port is reachable on every node's public IP. Anyone who can reach it may be able to pull images cached on the node, including private images. Before using Spegel with private images, add a default-deny [network policy](/docs/hetzner/apalla/security/segment-with-network-policies) to the `spegel` namespace that allows only the traffic Spegel needs: - Traffic between Spegel pods on TCP ports `5000` and `5001` and UDP port `5001`, which they use to discover each other and exchange image layers - DNS, for peer discovery - Traffic from the nodes to port `5000`, which containerd uses to reach the local cache > [!WARNING] > Spegel shares private images inside the cluster. Once a node has pulled a private image, pods on other nodes can retrieve it from the cache without their own registry pull credentials. This also applies when `imagePullPolicy: Always` is set. ## Related - [Pull images from a private registry](/docs/hetzner/apalla/workloads/delivery/pull-from-a-private-registry)