Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 6df2965

Browse files
committed
document local minikube. Fixes tilt-dev/tilt#3193
1 parent 0b79337 commit 6df2965

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,68 @@
11
# minikube-local
2+
23
The best way to set minikube up for local development
4+
5+
[![Build Status](https://circleci.com/gh/tilt-dev/minikube-local/tree/master.svg?style=shield)](https://circleci.com/gh/tilt-dev/minikube-local)
6+
7+
When using Tilt with a [Minikube](https://minikube.sigs.k8s.io/docs/) cluster,
8+
we recommend using a local registry for faster image pushing and pulling.
9+
10+
This repo documents the best way to set it up.
11+
12+
## Why use Minikube with a local registry?
13+
14+
Minikube offers many different ways to get your app into the cluster.
15+
16+
Using a local registry is the best method for iterative app development.
17+
18+
- Unlike with a remote registry, the image stays local to your machine, with no
19+
network traffic to wait on or credentials to setup.
20+
21+
- Unlike with an in-cluster builder, you can reset the cluster without deleting
22+
the image cache.
23+
24+
- Unlike with loading into the container runtime, docker will skip pushing any
25+
layers that already exist in the registry.
26+
27+
Over all these approaches, a local registry has good speed, incremental caching,
28+
and few footguns. But setting it up is awkward and fiddly. This script makes it
29+
easy.
30+
31+
## How to Try It
32+
33+
1) Install [Minikube](https://minikube.sigs.k8s.io/docs/)
34+
35+
2) Copy the [minikube-with-registry.sh](minikube-with-registry.sh) script somewhere on your path.
36+
37+
3) Create a cluster with `minikube-with-registry.sh`. Currently it creates the registry at port 5000.
38+
39+
```
40+
minikube-with-registry.sh
41+
```
42+
43+
4) Try pushing an image.
44+
45+
```
46+
docker tag alpine localhost:5000/alpine
47+
docker push localhost:5000/alpine
48+
```
49+
50+
You can now use the image name `localhost:5000/alpine` in any resources you deploy to the cluster.
51+
52+
[Tilt](https://tilt.dev) will automatically detect the local registry created by this script.
53+
54+
## Thanks to
55+
56+
High five to [MicroK8s](https://github.com/ubuntu/microk8s) for the initial local registry feature
57+
that inspired a lot of this work.
58+
59+
The Kind team ran with this, writing up documentation and hooks for how to [set up a local registry](https://kind.sigs.k8s.io/docs/user/local-registry/) with Kind.
60+
61+
This repo adapts the Kind team's approach and applies the local registry configmap, so that tools
62+
like Tilt can discover the local-registry. This protocol is a [Kubernetes Enhancement Proposal](https://github.com/kubernetes/enhancements/issues/1755).
63+
64+
## License
65+
66+
Copyright 2020 Windmill Engineering
67+
68+
Licensed under [the Apache License, Version 2.0](LICENSE)

minikube-with-registry.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
#
3+
# Adapted from:
4+
# https://github.com/kubernetes-sigs/kind/commits/master/site/static/examples/kind-with-registry.sh
5+
#
6+
# Copyright 2020 The Kubernetes Project
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License");
9+
# you may not use this file except in compliance with the License.
10+
# You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
set -o errexit
21+
22+
# desired profile name; default is ""
23+
MINIKUBE_PROFILE_NAME="${MINIKUBE_PROFILE_NAME:-minikube}"
24+
25+
reg_name='minikube-registry'
26+
reg_port='5000'
27+
28+
# create registry container unless it already exists
29+
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
30+
if [ "${running}" != 'true' ]; then
31+
docker run \
32+
-d --restart=always -p "${reg_port}:5000" --name "${reg_name}" \
33+
registry:2
34+
fi
35+
36+
reg_host="$(docker inspect -f '{{.NetworkSettings.IPAddress}}' "${reg_name}")"
37+
echo "Registry Host: ${reg_host}"
38+
39+
# create a cluster
40+
minikube start -p "$MINIKUBE_PROFILE_NAME" --driver=docker --container-runtime=containerd
41+
42+
# patch the container runtime
43+
# this is the most annoying sed expression i've ever had to write
44+
minikube ssh sudo sed "\-i" "s,\\\[plugins.cri.registry.mirrors\\\],[plugins.cri.registry.mirrors]\\\n\ \ \ \ \ \ \ \ [plugins.cri.registry.mirrors.\\\"localhost:${reg_port}\\\"]\\\n\ \ \ \ \ \ \ \ \ \ endpoint\ =\ [\\\"http://${reg_host}:${reg_port}\\\"]," /etc/containerd/config.toml
45+
46+
# restart the container runtime
47+
minikube ssh sudo systemctl restart containerd
48+
49+
# document the registry
50+
cat <<EOF | kubectl apply -f -
51+
apiVersion: v1
52+
kind: ConfigMap
53+
metadata:
54+
name: local-registry-hosting
55+
namespace: kube-public
56+
data:
57+
localRegistryHosting.v1: |
58+
host: "localhost:${reg_port}"
59+
help: "https://github.com/tilt-dev/minikube-local"
60+
EOF

test/pod.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: minikube-test
5+
labels:
6+
app: minikube-test
7+
spec:
8+
containers:
9+
- name: minikube-test
10+
image: localhost:5000/busybox
11+
command: ["sh", "-c", "busybox httpd -f -p 8000"]
12+
ports:
13+
- containerPort: 8000

test/test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
#
3+
# Make sure the local registry works as expected.
4+
5+
set -ex
6+
7+
cd $(dirname $0)
8+
9+
docker pull busybox
10+
docker tag busybox localhost:5000/busybox
11+
docker push localhost:5000/busybox
12+
kubectl delete -f pod.yaml --ignore-not-found
13+
kubectl create -f pod.yaml
14+
kubectl wait --for=condition=ready pod/minikube-test --timeout=60s

0 commit comments

Comments
 (0)