zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/examples/kind/kind-with-registry.sh (about) 1 #!/bin/sh 2 set -o errexit 3 4 # Reference: https://kind.sigs.k8s.io/docs/user/local-registry/ 5 6 # set no_proxy if applicable 7 if [ ! -z "${no_proxy}" ]; then 8 echo "Updating no_proxy env var"; 9 export no_proxy=${no_proxy},kind-registry; 10 export NO_PROXY=${no_proxy}; 11 fi 12 13 # create registry container unless it already exists 14 reg_name='kind-registry' 15 reg_port='5001' 16 if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then 17 docker run \ 18 -d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \ 19 ghcr.io/project-zot/zot-minimal-linux-amd64:latest 20 fi 21 22 # create a cluster with the local registry enabled in containerd 23 cat <<EOF | kind create cluster --config=- 24 kind: Cluster 25 apiVersion: kind.x-k8s.io/v1alpha4 26 containerdConfigPatches: 27 - |- 28 [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"] 29 endpoint = ["http://${reg_name}:5000"] 30 EOF 31 32 # connect the registry to the cluster network if not already connected 33 if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then 34 docker network connect "kind" "${reg_name}" 35 fi 36 37 # Document the local registry 38 # https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry 39 cat <<EOF | kubectl apply -f - 40 apiVersion: v1 41 kind: ConfigMap 42 metadata: 43 name: local-registry-hosting 44 namespace: kube-public 45 data: 46 localRegistryHosting.v1: | 47 host: "localhost:${reg_port}" 48 help: "https://kind.sigs.k8s.io/docs/user/local-registry/" 49 EOF 50 51 # Copy an image 52 skopeo copy --format=oci --dest-tls-verify=false docker://gcr.io/google-samples/hello-app:1.0 docker://localhost:5001/hello-app:1.0 53 54 # Deploy 55 kubectl create deployment hello-server --image=localhost:5001/hello-app:1.0 56 57 # Check 58 echo "Waiting for deployment/hello-server to be ready ..." 59 kubectl wait deployment -n default hello-server --for condition=Available=True --timeout=90s 60 61 # cleanup 62 echo "Press a key to begin cleanup ..." 63 read KEYPRESS 64 kind delete cluster 65 docker stop kind-registry 66 docker rm kind-registry