1
1
#! /bin/sh
2
2
set -o errexit
3
3
4
- # create registry container unless it already exists
4
+ # 1. Create registry container unless it already exists
5
5
reg_name=' kind-registry'
6
6
reg_port=' 5001'
7
7
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
10
10
registry:2
11
11
fi
12
12
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
14
21
cat << EOF | kind create cluster --config=-
15
22
kind: Cluster
16
23
apiVersion: kind.x-k8s.io/v1alpha4
17
24
containerdConfigPatches:
18
25
- |-
19
26
[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
26
29
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"]
29
43
EOF
44
+ done
30
45
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
32
48
if [ " $( docker inspect -f=' {{json .NetworkSettings.Networks.kind}}' " ${reg_name} " ) " = ' null' ]; then
33
49
docker network connect " kind" " ${reg_name} "
34
50
fi
35
51
36
- # Document the local registry
52
+ # 5. Document the local registry
37
53
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
38
54
cat << EOF | kubectl apply -f -
39
55
apiVersion: v1
46
62
host: "localhost:${reg_port} "
47
63
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
48
64
EOF
49
-
0 commit comments