Skip to content

Commit 8ae519b

Browse files
Add local kind registry for Tilt development setup
This change introduces hack/kind-with-registry.sh, adapted from https://kind.sigs.k8s.io/docs/user/local-registry and inspired by the now-archived https://github.com/tilt-dev/kind-local, and wires it into the make kind-create and make kind-delete targets. A local registry is preferred over alternatives such as 'kind load docker-image' because Docker layer caching applies when pushing to a registry: layers that already exist in the registry are skipped, so only the changed layers are transferred. With kind load every push uploads the full image regardless of what changed. In addition, all traffic stays on the local machine with no network round-trips to a remote registry. Tilt (v0.12.0+) auto-detects the registry through the KEP-1755 local-registry-hosting ConfigMap published in kube-public and handles the image-tagging dance automatically. The script starts a registry:3 container bound to localhost:5000, creates the kind cluster (requires kind v0.27.0+), configures each node's containerd to resolve localhost:5000 to the registry container via /etc/containerd/certs.d/localhost:<port>/hosts.toml, connects the registry container to the kind Docker network so that the nodes can reach it by name, and publishes the local-registry-hosting ConfigMap. make kind-delete tears down both the cluster and the registry container.
1 parent 48af92b commit 8ae519b

3 files changed

Lines changed: 78 additions & 10 deletions

File tree

‎Makefile‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ kind-create: FORCE
111111
echo "Kind is not installed. Please install Kind manually."; \
112112
exit 1; \
113113
}
114-
@kind get clusters | grep -q $(KIND_CLUSTER) || { \
115-
printf "\e[1;36m>> kind create cluster --name=$(KIND_CLUSTER)\e[0m\n"; \
116-
kind create cluster --name=$(KIND_CLUSTER); \
117-
}
114+
KIND_CLUSTER_NAME=$(KIND_CLUSTER) CONTAINER_TOOL=$(CONTAINER_TOOL) ./hack/kind-with-registry.sh
118115

119116
# Delete the Kind cluster created for local development and testing.
120117
kind-delete: FORCE
@@ -123,7 +120,8 @@ kind-delete: FORCE
123120
exit 1; \
124121
}
125122
@printf "\e[1;36m>> kind delete cluster --name=$(KIND_CLUSTER)\e[0m\n"
126-
@kind delete cluster --name=$(KIND_CLUSTER)
123+
KIND_EXPERIMENTAL_PROVIDER=$(CONTAINER_TOOL) kind delete cluster --name=$(KIND_CLUSTER)
124+
$(CONTAINER_TOOL) stop kind-registry && $(CONTAINER_TOOL) rm kind-registry
127125

128126
tilt-up: FORCE kind-create
129127
@command -v tilt >/dev/null 2>&1 || { \

‎Makefile.maker.yaml‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ verbatim: |
149149
echo "Kind is not installed. Please install Kind manually."; \
150150
exit 1; \
151151
}
152-
@kind get clusters | grep -q $(KIND_CLUSTER) || { \
153-
printf "\e[1;36m>> kind create cluster --name=$(KIND_CLUSTER)\e[0m\n"; \
154-
kind create cluster --name=$(KIND_CLUSTER); \
155-
}
152+
KIND_CLUSTER_NAME=$(KIND_CLUSTER) CONTAINER_TOOL=$(CONTAINER_TOOL) ./hack/kind-with-registry.sh
156153
157154
# Delete the Kind cluster created for local development and testing.
158155
kind-delete: FORCE
@@ -161,7 +158,8 @@ verbatim: |
161158
exit 1; \
162159
}
163160
@printf "\e[1;36m>> kind delete cluster --name=$(KIND_CLUSTER)\e[0m\n"
164-
@kind delete cluster --name=$(KIND_CLUSTER)
161+
KIND_EXPERIMENTAL_PROVIDER=$(CONTAINER_TOOL) kind delete cluster --name=$(KIND_CLUSTER)
162+
$(CONTAINER_TOOL) stop kind-registry && $(CONTAINER_TOOL) rm kind-registry
165163
166164
tilt-up: FORCE kind-create
167165
@command -v tilt >/dev/null 2>&1 || { \

‎hack/kind-with-registry.sh‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
# SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and IronCore contributors
3+
# SPDX-License-Identifier: Apache-2.0
4+
set -o errexit
5+
set -o nounset
6+
set -o pipefail
7+
8+
CONTAINER_TOOL="${CONTAINER_TOOL:-docker}"
9+
KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-kind}"
10+
export KIND_EXPERIMENTAL_PROVIDER="${CONTAINER_TOOL}"
11+
12+
# Exit early if the cluster already exists
13+
if kind get clusters | grep -q "^${KIND_CLUSTER_NAME}$"; then
14+
echo "Cluster ${KIND_CLUSTER_NAME} already exists"
15+
exit 0
16+
fi
17+
18+
# 1. Create registry container unless it already exists
19+
REGISTRY_NAME='kind-registry'
20+
REGISTRY_PORT="${KIND_REGISTRY_PORT:-5000}"
21+
if [ "$("${CONTAINER_TOOL}" inspect -f '{{.State.Running}}' "${REGISTRY_NAME}" 2>/dev/null || true)" != 'true' ]; then
22+
"${CONTAINER_TOOL}" run -d --restart=always -p "127.0.0.1:${REGISTRY_PORT}:5000" --network bridge --name "${REGISTRY_NAME}" registry:3
23+
fi
24+
25+
# 2. Create kind cluster
26+
cat <<EOF | kind create cluster --config=-
27+
kind: Cluster
28+
apiVersion: kind.x-k8s.io/v1alpha4
29+
name: ${KIND_CLUSTER_NAME}
30+
nodes:
31+
- role: control-plane
32+
labels:
33+
topology.kubernetes.io/zone: eu-de-1a
34+
EOF
35+
36+
# 3. Add the registry config to the nodes
37+
#
38+
# This is necessary because localhost resolves to loopback addresses that are
39+
# network-namespace local.
40+
# In other words: localhost in the container is not localhost on the host.
41+
#
42+
# We want a consistent name that works from both ends, so we tell containerd to
43+
# alias localhost:${reg_port} to the registry container when pulling images
44+
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${REGISTRY_PORT}"
45+
for node in $(kind get nodes); do
46+
"${CONTAINER_TOOL}" exec "${node}" mkdir -p "${REGISTRY_DIR}"
47+
cat <<EOF | "${CONTAINER_TOOL}" exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
48+
[host."http://${REGISTRY_NAME}:5000"]
49+
EOF
50+
done
51+
52+
# 4. Connect the registry to the cluster network if not already connected
53+
# This allows kind to bootstrap the network but ensures they're on the same network
54+
if [ "$("${CONTAINER_TOOL}" inspect -f='{{json .NetworkSettings.Networks.kind}}' "${REGISTRY_NAME}")" = 'null' ]; then
55+
"${CONTAINER_TOOL}" network connect "kind" "${REGISTRY_NAME}"
56+
fi
57+
58+
# 5. Document the local registry
59+
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
60+
cat <<EOF | kubectl apply -f -
61+
apiVersion: v1
62+
kind: ConfigMap
63+
metadata:
64+
name: local-registry-hosting
65+
namespace: kube-public
66+
data:
67+
localRegistryHosting.v1: |
68+
host: "localhost:${REGISTRY_PORT}"
69+
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
70+
EOF
71+
72+
kubectl wait --for=condition=Ready --timeout=300s "node/${KIND_CLUSTER_NAME}-control-plane"

0 commit comments

Comments
 (0)