github.com/castai/kvisor@v1.7.1-0.20240516114728-b3572a2607b5/tools/localenv/setup.sh (about) 1 #!/usr/bin/env bash 2 3 set -ex 4 5 cluster_name="kind" 6 7 if ! command -v kind &> /dev/null; then 8 echo 'binary "kind" not found in PATH. Is it installed?' >&2 9 exit 1 10 fi 11 12 # create registry container unless it already exists 13 reg_name='kind-registry' 14 reg_port='5000' 15 running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" 16 if [ "${running}" != 'true' ]; then 17 docker run \ 18 -d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \ 19 registry:2 20 fi 21 22 if kind get clusters | grep -E "^${cluster_name}$" 2>/dev/null; then 23 echo "Cluster with name '${cluster_name}' already exists, skipping creation. Make sure it matches the config required." >&2 24 else 25 26 # create a cluster with the local registry enabled in containerd 27 cat <<EOF | kind create cluster --config=- 28 kind: Cluster 29 apiVersion: kind.x-k8s.io/v1alpha4 30 name: ${cluster_name} 31 nodes: 32 - role: control-plane 33 34 containerdConfigPatches: 35 - |- 36 [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"] 37 endpoint = ["http://${reg_name}:${reg_port}"] 38 [plugins."io.containerd.grpc.v1.cri".containerd] 39 discard_unpacked_layers = false 40 EOF 41 fi 42 43 # connect the registry to the cluster network 44 # (the network may already be connected) 45 docker network connect "kind" "${reg_name}" || true 46 47 # Document the local registry 48 # https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry 49 cat <<EOF | kubectl apply -f - 50 apiVersion: v1 51 kind: ConfigMap 52 metadata: 53 name: local-registry-hosting 54 namespace: kube-public 55 data: 56 localRegistryHosting.v1: | 57 host: "localhost:${reg_port}" 58 help: "https://kind.sigs.k8s.io/docs/user/local-registry/" 59 EOF 60 61 kind export kubeconfig --name "$cluster_name"