2
2
set -o errexit
3
3
4
4
# create registry container unless it already exists
5
+ # http://kind-registry.local:5000
6
+ # curl -s -X GET kind-registry.local:5000/v2/_catalog | jq .
5
7
reg_name=' kind-registry.local'
6
8
reg_port=' 5000'
7
9
if [ " $( docker inspect -f ' {{.State.Running}}' " ${reg_name} " 2> /dev/null || true) " != ' true' ]; then
@@ -16,10 +18,26 @@ kind: Cluster
16
18
apiVersion: kind.x-k8s.io/v1alpha4
17
19
containerdConfigPatches:
18
20
- |-
19
- [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost :${reg_port} "]
21
+ [plugins."io.containerd.grpc.v1.cri".registry.mirrors."${reg_name} :${reg_port} "]
20
22
endpoint = ["http://${reg_name} :5000"]
21
23
EOF
22
24
25
+ # 3. Add the registry config to the nodes
26
+ #
27
+ # This is necessary because localhost resolves to loopback addresses that are
28
+ # network-namespace local.
29
+ # In other words: localhost in the container is not localhost on the host.
30
+ #
31
+ # We want a consistent name that works from both ends, so we tell containerd to
32
+ # alias localhost:${reg_port} to the registry container when pulling images
33
+ REGISTRY_DIR=" /etc/containerd/certs.d/${reg_name} :${reg_port} "
34
+ for node in $( sudo kind get nodes) ; do
35
+ sudo docker exec " ${node} " mkdir -p " ${REGISTRY_DIR} "
36
+ cat << EOF | sudo docker exec -i "${node} " cp /dev/stdin "${REGISTRY_DIR} /hosts.toml"
37
+ [host."http://${reg_name} :${reg_port} "]
38
+ EOF
39
+ done
40
+
23
41
# connect the registry to the cluster network if not already connected
24
42
if [ " $( docker inspect -f=' {{json .NetworkSettings.Networks.kind}}' " ${reg_name} " ) " = ' null' ]; then
25
43
docker network connect " kind" " ${reg_name} "
0 commit comments