In-cluster registry¶
Maturity: preview
New in 0.14.0. Its parameters may still change in a minor release, with a changelog entry. See the Roadmap for every feature’s status.
Registry.in_cluster(on="NODE") is one registry inside the cluster that
every node pulls from by one stable name. Use it when workloads run on
several nodes and you do not want a hosted registry: images are pushed once,
by digest, and any node pulls them. For a single node, the
Node-local registry needs nothing on the node; for a hosted registry,
use Registry("oci://host/prefix").
from piceli import App, Build, Pipeline, Registry, Target
registry = Registry.in_cluster(on="worker-1", storage="20Gi")
pipeline = Pipeline(
app,
target,
build=images,
deliver=registry, # images go to piceli-registry.piceli-system.svc:5000/<app>/…
)
Install it once per cluster, then deploy as usual:
$ piceli registry install deploy/app.py:pipeline # plan, exit 3, prints the hash
$ piceli registry install deploy/app.py:pipeline --approve sha256:…
$ piceli registry status deploy/app.py:pipeline
registry piceli-registry.piceli-system.svc:5000: ready
pod piceli-registry-6f9c… on worker-1: Running (ready)
mirror on control-plane: ready
mirror on worker-1: ready
mirror on worker-2: ready
storage piceli-registry-storage: Bound, 20Gi, 1048576 bytes used (the claim's volume)
$ piceli deploy deploy/app.py:pipeline --plan
The argument is a pipeline whose deliver= is Registry.in_cluster(…) (its
target names the cluster), the Registry.in_cluster(…) value itself, a
declared piceli.infra.Cluster with registry=Registry.in_cluster(…)
(infra.py:my_cluster, reached through its credential profile, whose API
server must be the declared api), or the composition module that declares
it (infra.py). status, install, uninstall and forward all take it.
Without it,
--on NODE --storage 20Gi --port 5000 --namespace piceli-system describe the
registry and --kubeconfig FILE --context NAME (or --profile NAME) name the
cluster; Piceli never uses the current context.
What is installed¶
In the namespace piceli-system (namespace=):
Object |
Purpose |
|---|---|
|
The complete registry configuration (no debug listener; deletes allowed for Registry retention). |
|
The images ( |
|
A stable ClusterIP on |
|
One replica of the digest-pinned |
|
The node agent: one pod on every containerd node (every taint tolerated) that writes the containerd mirror. |
|
The k3s node agent: one pod on every k3s node that merges the mirror into |
piceli registry uninstall plans the removal (exit 3, then --approve HASH); it keeps the namespace and, without --delete-storage, the claim
with the images.
The stable name¶
Every image is referenced as
<name>.<namespace>.svc:<port>/<repository>/<image>@sha256:<manifest digest>
piceli-registry.piceli-system.svc:5000/shop/web@sha256:…
The repository prefix is the app name (repository= to change it), so
several apps share one registry.
Pods (cluster build Jobs, the GitOps controller) resolve the name with cluster DNS and reach the Service directly.
Nodes do not use cluster DNS. The node agent writes
/etc/containerd/certs.d/piceli-registry.piceli-system.svc:5000/hosts.tomlon every node:server = "http://10.96.12.34:5000" [host."http://10.96.12.34:5000"] capabilities = ["pull", "resolve"]
containerd then pulls that host from the Service’s ClusterIP (which kube-proxy routes from every node) over plain HTTP. Only this host is affected; every other registry keeps its configuration. The agent reads the ClusterIP from the variable the kubelet sets in every pod (
PICELI_REGISTRY_SERVICE_HOST); it removes the file when it stops (uninstall, drain), so an uninstalled registry leaves nothing behind.
Plain HTTP is allowed only for a loopback registry or a name of the form
name.namespace.svc (or …svc.cluster.local), which never resolves outside
the cluster: traffic stays on the cluster network. Any other host still needs
TLS (plain-http-not-loopback).
Important
containerd reads certs.d only when its configuration sets config_path.
k3s nodes get their own agent (next section). On kind, add to the
cluster configuration:
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
piceli registry status shows each node’s agent as ready once the file is
written; it cannot see whether containerd reads that directory.
k3s nodes¶
k3s generates its containerd configuration itself, from
/etc/rancher/k3s/registries.yaml, when it starts. node_mirror= chooses
the node agent:
|
Nodes |
What the agent writes |
|---|---|---|
|
k3s nodes get the k3s agent, the others the containerd agent |
per node, as below |
|
every node |
|
|
every node |
|
With "auto" a node is a k3s node when it is labelled
piceli.io/runtime=k3s, or has no piceli.io/runtime label and k3s’s own
label node.kubernetes.io/instance-type=k3s. Cluster init sets
piceli.io/runtime on every declared node from the runtime it reports;
label a node by hand to override it.
The k3s agent (DaemonSet/piceli-registry-mirror-k3s):
merges this entry under
mirrors:in/etc/rancher/k3s/registries.yaml, between two marker comments, with the indentation of the entries already there, keeping the file’s mode; it creates the file when there is none:mirrors: # piceli:begin piceli-registry.piceli-system.svc:5000 "piceli-registry.piceli-system.svc:5000": endpoint: - "http://10.43.12.34:5000" # piceli:end piceli-registry.piceli-system.svc:5000
Every other entry (
mirrors,configs, credentials) is kept byte for byte, and nothing of the file is logged. A file it cannot edit that way (flow style such asmirrors: {}, JSON, a quoted or repeatedmirrorskey) is left untouched: the agent reportsunmergeableand stays not ready;writes the same
hosts.tomlinto k3s’s own/var/lib/rancher/k3s/agent/etc/containerd/certs.d/<host>/, which containerd reads at every pull, so the mirror works at once;on stop (uninstall, drain) removes its entry, its
hosts.toml, and the file itself when it had created it (an emptymirrors:key it added to an existing file stays).
Restarts. k3s reads registries.yaml only when it starts: the entry
there is what keeps the mirror after k3s restarts and regenerates certs.d.
Every current k3s configures containerd with config_path, so no restart is
needed. When a node’s k3s does not (an old k3s), its agent reports restart: needed, shown by piceli registry status, piceli cluster init and
piceli cluster status; restart k3s on that node (systemctl restart k3s,
or k3s-agent on agents) when convenient. Piceli never restarts k3s.
Each agent ends its start with one report line
(piceli-mirror: {"runtime": "k3s", "file": "written", "restart": "not-needed"}),
which status reads from its log; the mirror rows then show the runtime.
Storage use¶
piceli registry status reports the claim’s use, and says where it
comes from (storage.used_source in --json):
volume-stats: the kubelet’s statistics of the claim’s volume (needsgetonnodes/proxy), when that volume is the claim’s own filesystem;du:du -sk /var/lib/registryrun in the registry pod overpods/exec(read-only), when the kubelet’s figure is a filesystem the claim shares. On a node-path volume, such as k3s’s defaultlocal-path, the kubelet reports the node’s disk; that figure is instorage.filesystem(shared: true) and shown as such, never as the registry’s use;null(use unknown) when neither can be read.
$ piceli registry status infra.py:my_cluster
…
storage piceli-registry-storage: Bound, 40Gi, 2992108544 bytes used (du of /var/lib/registry in the registry pod); the filesystem that holds it is shared with the node: 26840000000 of 62000000000 bytes used
Cleaning up¶
Every deploy and cluster build adds images; nothing removes them on its own. Plan, approve, then run the registry’s garbage collector (details and the permissions needed in Registry retention):
piceli artifacts retention --cluster infra.py:my_cluster --delete # plan, exit 3
piceli artifacts retention --cluster infra.py:my_cluster --delete --approve <digest>
kubectl --kubeconfig FILE --context NAME -n piceli-system exec deploy/piceli-registry -- \
registry garbage-collect --dry-run /etc/distribution/config.yml
kubectl --kubeconfig FILE --context NAME -n piceli-system exec deploy/piceli-registry -- \
registry garbage-collect /etc/distribution/config.yml
piceli registry status infra.py:my_cluster
It keeps what runs, each workload’s rollback target and what Piceli uses (the
controller, the builder, the UI), and deletes the rest, including digest-only
images nothing names. Run the collector when no cluster build Job is running
(kubectl … get jobs -A -l piceli.io/build=true) and nothing pushes; never
with --delete-untagged (every image here is untagged).
How images get in¶
Who pushes |
How it reaches the registry |
|---|---|
|
A supervised, loopback-only |
A cluster build ( |
The Job pushes to |
Mirrors ( |
Copied by digest like a laptop push, then scanned for known vulnerabilities before they are used (0.94.0, Scanning images for known vulnerabilities (0.94.0)). |
Anything else |
|
piceli deploy --plan shows the registry in the deliver stage (registry piceli-registry.piceli-system.svc:5000: ready) and refuses with
cluster-registry-not-installed or cluster-registry-not-ready until it
serves. The deploy never installs or changes the registry, and its readiness
is not part of the plan hash. Pipelines that do not use it keep their 0.13
plan hashes.
Security¶
Anything that can reach the Service on the pod network can push and pull: the registry has no authentication in this release. Restrict it with a NetworkPolicy in
piceli-systemif pods you do not trust share the cluster.The node agent runs as root without any capability, and writes only its own directory under
mirror_dir.Images are always pulled by digest; a moved tag never changes what runs.
Verification on kind¶
A kind cluster (v0.32, Kubernetes 1.35, containerd with config_path set as
above) with one control-plane and two workers
(tests/integration/test_cluster_registry_kind.py): the registry was
installed on one worker; status became ready with the mirror ready on all
three nodes; a busybox image was pushed by digest from the laptop through the
Service port-forward; a pod pinned to the other worker with
imagePullPolicy: Always ran piceli-registry.piceli-system.svc:5000/e2e/busybox@sha256:…
(the node itself cannot resolve that name, so the pull went through the
mirror); after uninstall --delete-storage nothing was left in the
namespace and the agent had removed hosts.toml from the nodes.