Skip to content

Commit

Permalink
fix: update-kind-example-to-containerd_1.5
Browse files Browse the repository at this point in the history
Signed-off-by: dmitrynovik <[email protected]>
  • Loading branch information
dmitrychilli committed Feb 15, 2024
1 parent bd669e2 commit 6768f54
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion examples/local-kind-environment/scripts/kind-with-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
set -o errexit

# create registry container unless it already exists
# http://kind-registry.local:5000
# curl -s -X GET kind-registry.local:5000/v2/_catalog | jq .
reg_name='kind-registry.local'
reg_port='5000'
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
Expand All @@ -16,10 +18,26 @@ kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."${reg_name}:${reg_port}"]
endpoint = ["http://${reg_name}:5000"]
EOF

# 3. Add the registry config to the nodes
#
# This is necessary because localhost resolves to loopback addresses that are
# network-namespace local.
# In other words: localhost in the container is not localhost on the host.
#
# We want a consistent name that works from both ends, so we tell containerd to
# alias localhost:${reg_port} to the registry container when pulling images
REGISTRY_DIR="/etc/containerd/certs.d/${reg_name}:${reg_port}"
for node in $(sudo kind get nodes); do
sudo docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
cat <<EOF | sudo docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
[host."http://${reg_name}:${reg_port}"]
EOF
done

# connect the registry to the cluster network if not already connected
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
Expand Down

0 comments on commit 6768f54

Please sign in to comment.