Local Registry

With kind v0.6.0 there is a new config feature containerdConfigPatches that can be leveraged to configure insecure registries. The following recipe leverages this to enable a local registry.

Create A Cluster And Registry

The following shell script will create a local docker registry and a kind cluster with it enabled.

!/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}"\] 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

examples/kind-with-registry.sh —>
  1. #!/bin/sh
  2. set -o errexit

  3. create registry container unless it already exists

    reg_name=’kind-registry

  4. reg_port=’5000

  5. running=”$(docker inspect -f ‘{{.State.Running}}’ ${reg_name}” 2>/dev/null || true)”

  6. if [ ${running}” != true ]; then

  7. docker run \

  8. -d restart=always -p ${reg_port}:5000 name ${reg_name}” \

  9. registry:2

  10. fi

  11. create a cluster with the local registry enabled in containerd

    cat <<EOF | kind create cluster config=-

  12. kind: Cluster

  13. apiVersion: kind.x-k8s.io/v1alpha4

  14. containerdConfigPatches:

      • |-
      • [plugins.”io.containerd.grpc.v1.cri”.registry.mirrors.”localhost:${reg_port}”]
      • 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

    Using The Registry

    The registry can be used like this.

    1. First we’ll pull an image docker pull gcr.io/google-samples/hello-app:1.0
    2. 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
    3. Then we’ll push it to the registry docker push localhost:5000/hello-app:1.0
    4. And now we can use the image kubectl create deployment hello-server --image=localhost:5000/hello-app:1.0

    If you build your own image and tag it like localhost:5000/image:foo and then use it in kubernetes as localhost:5000/image:foo.