Skip to content

Commit 1eac075

Browse files
committed
Add example manifest of nerdctl ipfs registry on Kubernetes
Signed-off-by: Kohei Tokunaga <[email protected]>
1 parent 31aa63f commit 1eac075

File tree

3 files changed

+421
-0
lines changed

3 files changed

+421
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Example: Node-to-Node image sharing on Kubernetes using `nerdctl ipfs registry`
2+
3+
Usage:
4+
- Generate `bootstrap.yaml` by executing `bootstrap.yaml.sh` (e.g. `./bootstrap.yaml.sh > ${DIR_LOCATION}/bootstrap.yaml`)
5+
- [`ipfs-swarm-key-gen`](https://github.com/Kubuxu/go-ipfs-swarm-key-gen) is required (see https://github.com/ipfs/go-ipfs/blob/v0.10.0/docs/experimental-features.md#private-networks)
6+
- Deploy `bootstrap.yaml` and `nerdctl-ipfs-registry.yaml` (e.g. using `kubectl apply`)
7+
- Make sure nodes contain containerd >= v1.5.8
8+
9+
## Example on kind
10+
11+
Prepare cluster (make sure kind nodes contain containerd >= v1.5.8).
12+
13+
```console
14+
$ cat <<EOF > /tmp/kindconfig.yaml
15+
kind: Cluster
16+
apiVersion: kind.x-k8s.io/v1alpha4
17+
nodes:
18+
- role: control-plane
19+
- role: worker
20+
- role: worker
21+
EOF
22+
$ kind create cluster --image=kindest/node:v1.23.1 --config=/tmp/kindconfig.yaml
23+
$ ./bootstrap.yaml.sh > ./bootstrap.yaml
24+
$ kubectl apply -f .
25+
```
26+
27+
Prepare `kind-worker` (1st node) for importing an image to IPFS
28+
29+
(in `kind-worker`)
30+
31+
```console
32+
$ docker exec -it kind-worker /bin/bash
33+
(kind-worker)# NERDCTL_VERSION=0.15.0
34+
(kind-worker)# curl -sSL --output /tmp/nerdctl.tgz https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz
35+
(kind-worker)# tar zxvf /tmp/nerdctl.tgz -C /usr/local/bin/
36+
```
37+
38+
Add an image to `kind-worker`.
39+
40+
```console
41+
$ docker exec -it kind-worker /bin/bash
42+
(kind-worker)# mkdir -p /tmp/ipfsapi ; echo -n /ip4/127.0.0.1/tcp/5001 > /tmp/ipfsapi/api
43+
(kind-worker)# export IPFS_PATH=/tmp/ipfsapi
44+
(kind-worker)# nerdctl pull ghcr.io/stargz-containers/jenkins:2.60.3-org
45+
(kind-worker)# nerdctl push ipfs://ghcr.io/stargz-containers/jenkins:2.60.3-org
46+
(kind-worker)# nerdctl rmi ghcr.io/stargz-containers/jenkins:2.60.3-org
47+
```
48+
49+
The image added to `kind-worker` is shared to `kind-worker2` via IPFS.
50+
You can run this image on all worker nodes using the following manifest (assuming the image is added to IPFS as CID `localhost:5050/ipfs/bafkreife3j4tgtx23jcautprornrdp2p4g3j3ndnidzdlrpd7unbpnwkce`).
51+
52+
```console
53+
$ cat <<EOF | kubectl apply -f -
54+
apiVersion: apps/v1
55+
kind: Deployment
56+
metadata:
57+
name: jenkins
58+
spec:
59+
replicas: 2
60+
selector:
61+
matchLabels:
62+
app: jenkins
63+
template:
64+
metadata:
65+
labels:
66+
app: jenkins
67+
spec:
68+
containers:
69+
- name: jenkins
70+
image: localhost:5050/ipfs/bafkreife3j4tgtx23jcautprornrdp2p4g3j3ndnidzdlrpd7unbpnwkce
71+
resources:
72+
requests:
73+
cpu: 1
74+
EOF
75+
```
76+
77+
The image runs on all nodes.
78+
79+
```console
80+
$ kubectl get pods -owide | grep jenkins
81+
jenkins-7bd8f96d79-2jbc6 1/1 Running 0 69s 10.244.1.3 kind-worker <none> <none>
82+
jenkins-7bd8f96d79-jb5lm 1/1 Running 0 69s 10.244.2.4 kind-worker2 <none> <none>
83+
```
84+
85+
## Example Dockerfile of nerdctl
86+
87+
```Dockerfile
88+
FROM ubuntu:20.04
89+
ARG NERDCTL_VERSION=0.16.0
90+
RUN apt-get update -y && apt-get install -y curl && \
91+
curl -sSL --output /tmp/nerdctl.tgz https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-${TARGETARCH:-amd64}.tar.gz && \
92+
tar zxvf /tmp/nerdctl.tgz -C /usr/local/bin/ && \
93+
rm /tmp/nerdctl.tgz
94+
ENTRYPOINT [ "/usr/local/bin/nerdctl", "ipfs", "registry", "serve" ]
95+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Copyright The containerd Authors.
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Example script to prepare swarm key secret for IPFS bootstrap,
18+
# Example: ./bootstrap.yaml.sh > ./bootstrap.yaml
19+
20+
set -eu -o pipefail
21+
22+
for d in ipfs-swarm-key-gen ; do
23+
if ! command -v $d >/dev/null 2>&1 ; then
24+
echo "$d not found"
25+
exit 1
26+
fi
27+
done
28+
29+
SWARM_KEY=$(ipfs-swarm-key-gen | base64 | tr -d '\n')
30+
31+
cat <<EOF
32+
apiVersion: v1
33+
kind: Secret
34+
metadata:
35+
name: secret-config
36+
type: Opaque
37+
data:
38+
ipfs-swarm-key: $SWARM_KEY
39+
EOF

0 commit comments

Comments
 (0)