Skip to content

Commit e120e7a

Browse files
committed
add local private registry setup
This PR aims at adding local private docker registry setup with kind cluster. Prior this commit the doc is missing or the content is distributed.
1 parent 9605e3e commit e120e7a

File tree

1 file changed

+127
-1
lines changed

1 file changed

+127
-1
lines changed

docs/developers/local-setup.md

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This section provides guidelines for running Tekton on your local workstation vi
1212
Complete these prerequisites to run Tekton locally using Docker Desktop:
1313

1414
- Install the [required tools](https://github.com/tektoncd/pipeline/blob/main/DEVELOPMENT.md#requirements).
15-
- Install [Docker Desktop](https://www.docker.com/products/docker-desktop)
15+
- Install [Docker Desktop](https://www.docker.com/products/docker-desktop)
1616
- Configure Docker Desktop ([Mac](https://docs.docker.com/docker-for-mac/#resources), [Windows](https://docs.docker.com/docker-for-windows/#resources))to use six CPUs, 10 GB of RAM and 2GB of swap space.
1717
- Set `host.docker.internal:5000` as an insecure registry with Docker for Desktop. See the [Docker insecure registry documentation](https://docs.docker.com/registry/insecure/).
1818
for details.
@@ -82,3 +82,129 @@ If you wish to use a different image URL, you can add the appropriate line to mi
8282
### Reconfigure logging
8383

8484
See the information in the "Docker for Desktop" section
85+
86+
## Using kind and local docker registry
87+
88+
### Prerequisites
89+
90+
Complete these prerequisites to run Tekton locally using Kind:
91+
92+
- Install the [required tools](https://github.com/tektoncd/pipeline/blob/main/DEVELOPMENT.md#requirements).
93+
- Install [Docker](https://www.docker.com/get-started).
94+
- Install [kind](https://kind.sigs.k8s.io/).
95+
96+
### Use local registry without authentication
97+
98+
See [Using KinD](https://github.com/tektoncd/pipeline/blob/main/DEVELOPMENT.md#using-kind).
99+
100+
### Use local private registry
101+
102+
1. Create password file with basic auth.
103+
104+
```bash
105+
export TEST_USER=testuser
106+
export TEST_PASS=testpassword
107+
if [ ! -f auth ]; then
108+
mkdir auth
109+
fi
110+
docker run \
111+
--entrypoint htpasswd \
112+
httpd:2 -Bbn $TEST_USER $TEST_PASS > auth/htpasswd
113+
```
114+
115+
2. Start kind cluster and local private registry
116+
117+
118+
Execute the script.
119+
120+
```shell
121+
#!/bin/sh
122+
set -o errexit
123+
124+
# create registry container unless it already exists
125+
reg_name='kind-registry'
126+
reg_port='5000'
127+
running="$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)"
128+
if [ "${running}" != 'true' ]; then
129+
docker run \
130+
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
131+
-v "$(pwd)"/auth:/auth \
132+
-e "REGISTRY_AUTH=htpasswd" \
133+
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
134+
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
135+
registry:2
136+
fi
137+
138+
# create a cluster with the local registry enabled in containerd
139+
cat <<EOF | kind create cluster --config=-
140+
kind: Cluster
141+
apiVersion: kind.x-k8s.io/v1alpha4
142+
containerdConfigPatches:
143+
- |-
144+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
145+
endpoint = ["http://${reg_name}:5000"]
146+
EOF
147+
148+
# connect the registry to the cluster network
149+
# (the network may already be connected)
150+
docker network connect "kind" "${reg_name}" || true
151+
152+
# Document the local registry
153+
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
154+
cat <<EOF | kubectl apply -f -
155+
apiVersion: v1
156+
kind: ConfigMap
157+
metadata:
158+
name: local-registry-hosting
159+
namespace: kube-public
160+
data:
161+
localRegistryHosting.v1: |
162+
host: "localhost:${reg_port}"
163+
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
164+
EOF
165+
166+
```
167+
168+
3. Install tekton [pipeline](https://github.com/tektoncd/pipeline/blob/main/docs/install.md) and create the secret in cluster.
169+
170+
```bash
171+
kubectl create secret docker-registry secret-tekton \
172+
--docker-username=$TEST_USER \
173+
--docker-password=$TEST_PASS \
174+
--docker-server=localhost:5000 \
175+
--namespace=tekton-pipelines
176+
```
177+
178+
4. Config [ko](https://github.com/google/ko#install) and add secret to service acount.
179+
180+
```bash
181+
export KO_DOCKER_REPO='localhost:5000'
182+
```
183+
184+
`200-serviceaccount.yaml`
185+
186+
```yaml
187+
apiVersion: v1
188+
kind: ServiceAccount
189+
metadata:
190+
name: tekton-pipelines-controller
191+
namespace: tekton-pipelines
192+
labels:
193+
app.kubernetes.io/component: controller
194+
app.kubernetes.io/instance: default
195+
app.kubernetes.io/part-of: tekton-pipelines
196+
imagePullSecrets:
197+
- name: secret-tekton
198+
---
199+
apiVersion: v1
200+
kind: ServiceAccount
201+
metadata:
202+
name: tekton-pipelines-webhook
203+
namespace: tekton-pipelines
204+
labels:
205+
app.kubernetes.io/component: webhook
206+
app.kubernetes.io/instance: default
207+
app.kubernetes.io/part-of: tekton-pipelines
208+
imagePullSecrets:
209+
- name: secret-tekton
210+
```

0 commit comments

Comments
 (0)