Skip to content

Commit 791b3dc

Browse files
committed
switch registry script to use containerd hosts dir
1 parent 4e40454 commit 791b3dc

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

site/static/examples/kind-with-registry.sh

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
set -o errexit
33

4-
# create registry container unless it already exists
4+
# 1. Create registry container unless it already exists
55
reg_name='kind-registry'
66
reg_port='5001'
77
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
@@ -10,30 +10,46 @@ if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true
1010
registry:2
1111
fi
1212

13-
# create a cluster with the local registry enabled in containerd
13+
# 2. Create kind cluster with containerd registry config dir enabled
14+
# TODO: kind will eventually enable this by default and this patch will
15+
# be unnecessary.
16+
#
17+
# See:
18+
# https://github.com/kubernetes-sigs/kind/issues/2875
19+
# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration
20+
# See: https://github.com/containerd/containerd/blob/main/docs/hosts.md
1421
cat <<EOF | kind create cluster --config=-
1522
kind: Cluster
1623
apiVersion: kind.x-k8s.io/v1alpha4
1724
containerdConfigPatches:
1825
- |-
1926
[plugins."io.containerd.grpc.v1.cri".registry]
20-
# ensure config_path is disabled so the config below is respected
21-
# TODO: kind will eventually migrate to using config_path
22-
# see:
23-
# https://github.com/kubernetes-sigs/kind/issues/2875
24-
# https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration
25-
config_path = ""
27+
config_path = "/etc/containerd/certs.d"
28+
EOF
2629

27-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
28-
endpoint = ["http://${reg_name}:5000"]
30+
# 3. Add the registry config to the nodes
31+
#
32+
# This is necessary because localhost resolves to loopback addresses that are
33+
# network-namespace local.
34+
# In other words: localhost in the container is not localhost on the host.
35+
#
36+
# We want a consistent name that works from both ends, so we tell containerd to
37+
# alias localhost:${reg_port} to the registry container when pulling images
38+
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"
39+
for node in $(kind get nodes); do
40+
docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
41+
cat <<EOF | docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
42+
[host."http://${reg_name}:5000"]
2943
EOF
44+
done
3045

31-
# connect the registry to the cluster network if not already connected
46+
# 4. Connect the registry to the cluster network if not already connected
47+
# This allows kind to bootstrap the network but ensures they're on the same network
3248
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
3349
docker network connect "kind" "${reg_name}"
3450
fi
3551

36-
# Document the local registry
52+
# 5. Document the local registry
3753
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
3854
cat <<EOF | kubectl apply -f -
3955
apiVersion: v1
@@ -46,4 +62,3 @@ data:
4662
host: "localhost:${reg_port}"
4763
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
4864
EOF
49-

0 commit comments

Comments
 (0)