Skip to content

Commit 3376e0b

Browse files
Create kind cluster with local registry plugin
1 parent 43b0a20 commit 3376e0b

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

Diff for: deployment/docker/registry/createRegistry.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
set -o errexit
3+
4+
# 1. Create registry container unless it already exists
5+
reg_name='kind-registry'
6+
reg_port='5001'
7+
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
8+
docker run \
9+
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
10+
registry:2
11+
fi
12+
13+
# 3. Add the registry config to the nodes
14+
#
15+
# This is necessary because localhost resolves to loopback addresses that are
16+
# network-namespace local.
17+
# In other words: localhost in the container is not localhost on the host.
18+
#
19+
# We want a consistent name that works from both ends, so we tell containerd to
20+
# alias localhost:${reg_port} to the registry container when pulling images
21+
REGISTRY_DIR="/etc/containerd/certs.d/localhost:${reg_port}"
22+
for node in $(kind get nodes -A); do
23+
docker exec "${node}" mkdir -p "${REGISTRY_DIR}"
24+
cat <<EOF | docker exec -i "${node}" cp /dev/stdin "${REGISTRY_DIR}/hosts.toml"
25+
[host."http://${reg_name}:5000"]
26+
EOF
27+
done
28+
29+
# 4. Connect the registry to the cluster network if not already connected
30+
# This allows kind to bootstrap the network but ensures they're on the same network
31+
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
32+
docker network connect "kind" "${reg_name}"
33+
fi
34+
35+
# 5. Document the local registry
36+
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
37+
cat <<EOF | kubectl apply -f -
38+
apiVersion: v1
39+
kind: ConfigMap
40+
metadata:
41+
name: local-registry-hosting
42+
namespace: kube-public
43+
data:
44+
localRegistryHosting.v1: |
45+
host: "localhost:${reg_port}"
46+
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
47+
EOF

Diff for: scripts/kind-cluster-config.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
containerdConfigPatches:
4+
- |-
5+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5001"]
6+
endpoint = ["http://kind-registry:5000"]

Diff for: scripts/setup-backstage.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22

33
# Setup a Kubernetes cluster with kind
4-
kind create cluster --image kindest/node:v1.26.6 --wait 5m --name backstage
4+
kind create cluster --image kindest/node:v1.26.6 --wait 5m --name backstage --config ./scripts/kind-cluster-config.yaml

0 commit comments

Comments
 (0)