Pull images faster from a local registry
This documents the in-development version. Switch to v2.3 for the latest stable release.
kuik copies the images your pods use to a registry close to your cluster, and routes new pods to the copy. Pulls get faster and steadier, and the distant registry is read once per image instead of once per node.
Best suited for
Section titled “Best suited for”- Your production clusters pull from a development registry (GitLab, Artifactory…) that is far away or busy
- Your source registry is overloaded, or rations pulls
- Image pulls are slow, and slow down rollouts, scale-ups and node replacements
- Your source registry is far from the cluster, in network, latency or egress cost
Benefits
Section titled “Benefits”- Pulls come from a registry next to the nodes: quicker and more stable
- Only the images your pods actually use are copied, never a whole registry
- The source stays a fallback: a copy that is not ready, or a local registry that is down, sends the pod to its original image
How it works
Section titled “How it works”An ImageMirror watches the pods it selects and copies their images under destination.path, the full original reference appended, with this cluster’s ID as a tag suffix: gitlab.example.com/team/app:1.4 is copied to registry.local.example.com/kuik/gitlab.example.com/team/app:1.4_<clusterID>.
With rewritePolicy: Always, the webhook places the copy ahead of the original on every new pod, once it checked the copy is there. Until the copy is made, the pod keeps its original image. A container with imagePullPolicy: Always is the exception, see Good to know.
Set it up
Section titled “Set it up”-
Prepare the local registry. It must accept nested repository paths (Harbor, Zot and the CNCF
distributionregistry do), and with cleanup on, tag deletion and its own garbage collection: see Destination requirements. -
Create 2 credentials in kuik’s namespace (
kuik-systemby default, adapt the commands otherwise): one for kuik to push, read, list and delete tags, one for the kubelet to pull. kuik copies the pull credential into every namespace the mirror’snamespaceSelectorselects, all of them when it is empty: anyone who can read Secrets there can read it. Set anamespaceSelectorto bound it (see Injected pull secrets). Skip the pull credential if the registry allows anonymous pulls.Terminal window kubectl create secret docker-registry local-registry-push --namespace kuik-system \--docker-server=registry.local.example.com --docker-username=<push user> --docker-password=<token>kubectl create secret docker-registry local-registry-pull --namespace kuik-system \--docker-server=registry.local.example.com --docker-username=<pull user> --docker-password=<token> -
Create the
ImageMirror:apiVersion: kuik.enix.io/v1alpha1kind: ImageMirrormetadata:name: local-registryspec:rewritePolicy: Alwaysdestination:path: registry.local.example.com/kuikmanage:auth:secretRef:name: local-registry-pushpull:auth:secretRef:name: local-registry-pullcleanup:retention: 168h -
Adjust the copy pace. kuik copies at most one image per source registry per
copy.interval, 3 minutes by default, to keep its share of a rate limit small: 100 images from one registry take 5 hours. For a registry you own, which does not ration pulls, lower it in the chart values (see Registry pacing):values.yaml config:registries:gitlab.example.com:copy:interval: 10s -
Once the copies are made, restart your workloads: kuik only rewrites pods at creation. The copies are made when
availablereachestracked:Terminal window kubectl get imagemirror local-registry -o jsonpath='{.status.images.copy}'# {"available":57,...,"tracked":57,...}
To mirror only some workloads, restrict the resource with namespaceSelector and podSelector, see Selecting workloads. To keep some images out, list them in excludeImages.
Check it works
Section titled “Check it works”The mirror reports how many images it holds, and which copies fail:
kubectl get imagemirrors# NAME DESTINATION POLICY READY OUTOFSYNC TRACKED AGE# local-registry registry.local.example.com/kuik Always True False 57 2dkubectl get imagemirror local-registry -o jsonpath='{.status.failedImageCopies}'A new pod runs the copy, and records the original image:
kubectl get pod <pod> -o jsonpath='{.metadata.annotations.kuik\.enix\.io/rewrites}'# {"app":{"by":"ImageMirror/local-registry","origin":"gitlab.example.com/team/app:1.4","rewrittenTo":"registry.local.example.com/kuik/gitlab.example.com/team/app:1.4_focused-turing-7f3a","policy":"Always"}}The first copy of an image emits an ImageCopied event on the mirror. Each failed copy emits ImageCopyFailed: copies are paced, so expect at most one per copy.interval and registry. Alert on kuik_image_copy_failed.
Good to know
Section titled “Good to know”- kuik reads a private source with the pull secrets of the pods that use the image. With the chart value
secretAccess.mode: restricted, declare the source’s credentials infallbackAuth. - A container with
imagePullPolicy: Alwaysasks for the latest digest of its tag: kuik tries its original first and the copy only as a fallback. Setwebhook.demoteMirrorWithPullPolicyAlwaystofalseto route it to the copy too. - A tag is copied once. If your tags move (
latest,main), setdriftPolicy: Syncto copy them again when their upstream digest changes, orWarnto be told. - A tag no pod uses any more is deleted from the local registry once
cleanup.retentionhas elapsed, so that a CronJob’s image survives between runs. kuik deletes tags only: the registry’s garbage collection frees the space. - Several clusters can share one local registry: each one writes its own tags, under its own cluster ID. Never give 2 clusters the same ID, see Cluster ID.