github.com/tilt-dev/tilt@v0.36.0/integration/kind-with-registry.sh (about) 1 #!/bin/sh 2 # 3 # Adapted from: 4 # https://github.com/kubernetes-sigs/kind/commits/master/site/static/examples/kind-with-registry.sh 5 # 6 # Copyright 2020 The Kubernetes Project 7 # 8 # Licensed under the Apache License, Version 2.0 (the "License"); 9 # you may not use this file except in compliance with the License. 10 # You may obtain a copy of the License at 11 # 12 # http://www.apache.org/licenses/LICENSE-2.0 13 # 14 # Unless required by applicable law or agreed to in writing, software 15 # distributed under the License is distributed on an "AS IS" BASIS, 16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 # See the License for the specific language governing permissions and 18 # limitations under the License. 19 20 set -o errexit 21 22 # desired cluster name; default is "kind" 23 KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-kind}" 24 25 kind_version=$(kind version) 26 kind_network='kind' 27 reg_name='kind-registry' 28 reg_port='5000' 29 case "${kind_version}" in 30 "kind v0.7."* | "kind v0.6."* | "kind v0.5."*) 31 kind_network='bridge' 32 ;; 33 esac 34 35 # create registry container unless it already exists 36 running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" 37 if [ "${running}" != 'true' ]; then 38 docker run \ 39 -d --restart=always -p "${reg_port}:5000" --name "${reg_name}" \ 40 registry:2 41 fi 42 43 reg_host="${reg_name}" 44 if [ "${kind_network}" = "bridge" ]; then 45 reg_host="$(docker inspect -f '{{.NetworkSettings.IPAddress}}' "${reg_name}")" 46 fi 47 echo "Registry Host: ${reg_host}" 48 49 # create a cluster with the local registry enabled in containerd 50 cat <<EOF | kind create cluster --name "${KIND_CLUSTER_NAME}" --config=- 51 kind: Cluster 52 apiVersion: kind.x-k8s.io/v1alpha4 53 containerdConfigPatches: 54 - |- 55 [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"] 56 endpoint = ["http://${reg_host}:${reg_port}"] 57 EOF 58 59 cat <<EOF | kubectl apply -f - 60 apiVersion: v1 61 kind: ConfigMap 62 metadata: 63 name: local-registry-hosting 64 namespace: kube-public 65 data: 66 localRegistryHosting.v1: | 67 host: "localhost:${reg_port}" 68 help: "https://kind.sigs.k8s.io/docs/user/local-registry/" 69 EOF 70 71 if [ "${kind_network}" != "bridge" ]; then 72 containers=$(docker network inspect ${kind_network} -f "{{range .Containers}}{{.Name}} {{end}}") 73 needs_connect="true" 74 for c in $containers; do 75 if [ "$c" = "${reg_name}" ]; then 76 needs_connect="false" 77 fi 78 done 79 if [ "${needs_connect}" = "true" ]; then 80 docker network connect "${kind_network}" "${reg_name}" || true 81 fi 82 fi 83