#!/usr/bin/env bash # # Copyright contributors to the Hyperledgendary Full Stack Asset Transfer project # # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # set -eo pipefail set -x KIND_CLUSTER_NAME=kind KIND_CLUSTER_IMAGE=${KIND_CLUSTER_IMAGE:-kindest/node:v1.35.1} # Important! k8s v1.25.0 brings breaking changes. KIND_API_SERVER_ADDRESS=${KIND_API_SERVER_ADDRESS:-127.0.0.1} KIND_API_SERVER_PORT=${KIND_API_SERVER_PORT:-8888} CONTAINER_REGISTRY_NAME=${CONTAINER_REGISTRY_NAME:-kind-registry} CONTAINER_REGISTRY_ADDRESS=${CONTAINER_REGISTRY_ADDRESS:-127.0.0.1} CONTAINER_REGISTRY_PORT=${CONTAINER_REGISTRY_PORT:-5000} function kind_with_nginx() { delete_cluster create_cluster start_nginx apply_coredns_override launch_docker_registry } # # Delete a kind cluster if it exists # function delete_cluster() { kind delete cluster --name $KIND_CLUSTER_NAME } # # Create a local KIND cluster # function create_cluster() { cat << EOF | kind create cluster --name $KIND_CLUSTER_NAME --image $KIND_CLUSTER_IMAGE --config=- --- kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane kubeadmConfigPatches: - | kind: InitConfiguration nodeRegistration: kubeletExtraArgs: node-labels: "ingress-ready=true" extraPortMappings: - containerPort: 80 hostPort: 80 protocol: TCP - containerPort: 443 hostPort: 443 protocol: TCP networking: apiServerAddress: ${KIND_API_SERVER_ADDRESS} apiServerPort: ${KIND_API_SERVER_PORT} # create a cluster with the local registry enabled in containerd containerdConfigPatches: - |- [plugins."io.containerd.grpc.v1.cri".registry] config_path = "/etc/containerd/certs.d" EOF # Configure registry for containerd 2.x using config_path mode for node in $(kind get nodes --name $KIND_CLUSTER_NAME); do docker exec "$node" mkdir -p "/etc/containerd/certs.d/localhost:${CONTAINER_REGISTRY_PORT}" docker exec "$node" sh -c "cat > /etc/containerd/certs.d/localhost:${CONTAINER_REGISTRY_PORT}/hosts.toml </dev/null || true)" if [ "${running}" != 'true' ]; then docker run \ --detach \ --restart always \ --name "${CONTAINER_REGISTRY_NAME}" \ --publish "${CONTAINER_REGISTRY_ADDRESS}:${CONTAINER_REGISTRY_PORT}:${CONTAINER_REGISTRY_PORT}" \ registry:2 fi # connect the registry to the cluster network # (the network may already be connected) docker network connect "kind" "${CONTAINER_REGISTRY_NAME}" || true # Document the local registry # https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry cat <