Skip to content

Instantly share code, notes, and snippets.

@danilobatistaqueiroz
Last active August 13, 2020 19:44
Show Gist options
  • Save danilobatistaqueiroz/d844b8d87fe33fdf176f506b60ac3fb6 to your computer and use it in GitHub Desktop.
Save danilobatistaqueiroz/d844b8d87fe33fdf176f506b60ac3fb6 to your computer and use it in GitHub Desktop.
cluster kind using local registry and an ingress configured
#!/bin/sh
set -o errexit
# create registry container unless it already exists
reg_name='kind-registry'
reg_port='5000'
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
if [ "${running}" != 'true' ]; then
docker run \
-d --restart=always -p "${reg_port}:5000" --name "${reg_name}" \
registry:2
fi
# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
endpoint = ["http://${reg_name}:${reg_port}"]
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
EOF
# connect the registry to the cluster network
docker network connect "kind" "${reg_name}"
# tell https://tilt.dev to use the registry
# https://docs.tilt.dev/choosing_clusters.html#discovering-the-registry
for node in $(kind get nodes); do
kubectl annotate node "${node}" "kind.x-k8s.io/registry=localhost:${reg_port}";
done

https://github.com/danilobatistaqueiroz/node_kind

kind delete cluster

chmod +x cluster-kind.bash ./cluster-kind.bash

The registry can be used like this.

First we'll pull an image docker pull gcr.io/google-samples/hello-app:1.0
Then we'll tag the image to use the local registry docker tag gcr.io/google-samples/hello-app:1.0 localhost:5000/hello-app:1.0
Then we'll push it to the registry docker push localhost:5000/hello-app:1.0
And now we can use the image kubectl create deployment hello-server --image=localhost:5000/hello-app:1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment