Skip to content

Commit 270b67b

Browse files
Add internal registry to KinD example
By default, our KinD example now will create a internal registry, then export the URL to be used by our kubernetes demo when pulling and pushing images
1 parent ad819a9 commit 270b67b

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ values-private.yaml
66

77
# Vim swapfiles
88
*.sw[po]
9+
10+
# Example temp files
11+
examples/kubernetes-in-docker/temp*

examples/kubernetes-in-docker/0_export_env_vars.sh

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ export TEST_APP_LOADBALANCER_SVCS="${TEST_APP_LOADBALANCER_SVCS:-false}"
2525
# build and push demo images to a registry so that the images can then be
2626
# pulled by KinD.
2727
#
28-
# These should be configured/customized in bootstrap.env
29-
check_env_var "DOCKER_REGISTRY_URL"
30-
check_env_var "DOCKER_REGISTRY_PATH"
31-
check_env_var "DOCKER_USERNAME"
32-
check_env_var "DOCKER_PASSWORD"
33-
check_env_var "DOCKER_EMAIL"
28+
# These should be configured/customized in customize.env
29+
export CREATE_DOCKER_INTERNAL_REGISTRY="${CREATE_DOCKER_INTERNAL_REGISTRY:-true}"
30+
if [[ "CREATE_DOCKER_INTERNAL_REGISTRY" == "false" ]]; then
31+
check_env_var "DOCKER_REGISTRY_URL"
32+
check_env_var "DOCKER_REGISTRY_PATH"
33+
check_env_var "DOCKER_USERNAME"
34+
check_env_var "DOCKER_PASSWORD"
35+
check_env_var "DOCKER_EMAIL"
36+
fi

examples/kubernetes-in-docker/1_create_kind_cluster.sh

+27
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,33 @@ fi
2424
# Check if KinD cluster has already been created
2525
if [ "$(kind get clusters | grep "^$KIND_CLUSTER_NAME$")" = "$KIND_CLUSTER_NAME" ]; then
2626
echo "KinD cluster '$KIND_CLUSTER_NAME' already exists. Skipping cluster creation."
27+
elif [[ $CREATE_DOCKER_INTERNAL_REGISTRY == "true" ]]; then
28+
announce "Creating KinD Cluster with local registry"
29+
30+
reg_name='kind-registry'
31+
reg_port='5000'
32+
33+
# create registry container unless it already exists
34+
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
35+
if [ "${running}" != 'true' ]; then
36+
docker run \
37+
-d --restart=always -p "${reg_port}:5000" --name "${reg_name}" --net=kind \
38+
registry:2
39+
fi
40+
reg_ip="$(docker inspect -f '{{.NetworkSettings.Networks.kind.IPAddress}}' "${reg_name}")"
41+
echo "Registry IP: ${reg_ip}"
42+
43+
# create a cluster with the local registry enabled in containerd
44+
cat <<EOF | kind create cluster --name "${KIND_CLUSTER_NAME}" --config=-
45+
kind: Cluster
46+
apiVersion: kind.x-k8s.io/v1alpha4
47+
containerdConfigPatches:
48+
- |-
49+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
50+
endpoint = ["http://${reg_ip}:${reg_port}"]
51+
EOF
52+
53+
export DOCKER_REGISTRY_URL="${reg_ip}:${reg_port}"
2754
else
2855
kind create cluster --name "$KIND_CLUSTER_NAME"
2956
fi

examples/kubernetes-in-docker/customize.env

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
# Uncomment and modify the settings below, and source the resulting file
44
# to customize the demo scripts that are in this directory.
55
#
6-
# NOTE: The DOCKER settings below are required to run the test scripts,
7-
# so at a minimum these environment settings must be changed.
6+
# NOTE: The DOCKER settings below are required, unless CREATE_DOCKER_INTERNAL_REGISTRY
7+
# is set to "true"
88

9-
# CHANGE THE FOLLOWING DOCKER CREDENTIAL ENVIRONMENT VARIABLES!!!
10-
# Docker registry credentials are required since the demo scripts need to
11-
# build and push demo images to a registry so that the images can then be
12-
# pulled by KinD. For example, if you are using your personal DockerHub
9+
# Docker registry credentials are need to build and push demo images
10+
# to a registry so that the images can then be pulled by KinD.
11+
# For example, if you are using your personal DockerHub
1312
# account, your environment settings might look something like this:
13+
# export CREATE_DOCKER_INTERNAL_REGISTRY="false"
1414
# export DOCKER_REGISTRY_URL="docker.io"
1515
# export DOCKER_REGISTRY_PATH="firstnamelastname"
1616
# export DOCKER_USERNAME="firstnamelastname"
1717
# export DOCKER_PASSWORD="GreatGooglyMoogly"
1818
# export DOCKER_EMAIL="[email protected]"
19+
#export CREATE_DOCKER_INTERNAL_REGISTRY="true"
1920
#export DOCKER_REGISTRY_URL="docker.io"
2021
#export DOCKER_REGISTRY_PATH="<your-dockerhub-org-or-username>"
2122
#export DOCKER_USERNAME="<your-dockerhub-username>"

0 commit comments

Comments
 (0)