22set -o errexit
33
44# 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 .
57reg_name=' kind-registry.local'
68reg_port=' 5000'
79if [ " $( docker inspect -f ' {{.State.Running}}' " ${reg_name} " 2> /dev/null || true) " != ' true' ]; then
@@ -16,10 +18,26 @@ kind: Cluster
1618apiVersion: kind.x-k8s.io/v1alpha4
1719containerdConfigPatches:
1820- |-
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} "]
2022 endpoint = ["http://${reg_name} :5000"]
2123EOF
2224
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+
2341# connect the registry to the cluster network if not already connected
2442if [ " $( docker inspect -f=' {{json .NetworkSettings.Networks.kind}}' " ${reg_name} " ) " = ' null' ]; then
2543 docker network connect " kind" " ${reg_name} "
0 commit comments