1. 创建项目
oc new-project ipfs-dev
2. 生成swarm key
go get -u github.com/Kubuxu/go-ipfs-swarm-key-gen/ipfs-swarm-key-gen
./ipfs-swarm-key-gen > swarm.key
3. 创建Secret
swarmkey的值由上一步生成
apiVersion: v1
data:
swarmkey: >-
base64(your swarmkey )
kind: Secret
metadata:
name: ipfs-swarmkey
namespace: ipfs-dev
type: Opaque
4. 创建StatefulSet
ipfs-staging用于临时存放操作数据
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: ipfs
name: ipfs-st
namespace: ipfs-dev
spec:
replicas: 4
revisionHistoryLimit: 10
selector:
matchLabels:
app: ipfs
serviceName: ipfs-headless-svc
template:
metadata:
labels:
app: ipfs
spec:
containers:
- args:
- >-
cp /swarm.key /data/ipfs/swarm.key; /sbin/tini -s --
/usr/local/bin/start_ipfs daemon --migrate=true
command:
- /bin/sh
- '-c'
image: 'ipfs/go-ipfs:v0.4.23'
imagePullPolicy: IfNotPresent
name: ipfs
ports:
- containerPort: 4001
name: swarm
protocol: TCP
- containerPort: 5001
name: api
protocol: TCP
- containerPort: 8080
name: gateway
protocol: TCP
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
volumeMounts:
- mountPath: /data/ipfs
name: ipfs-data
- mountPath: /export
name: ipfs-staging
- mountPath: /swarm.key
name: swarm-key
restartPolicy: Always
volumes:
- configMap:
defaultMode: 420
items:
- key: swarm.key
path: swarm.key
name: init-bootstrap
name: swarm-key
volumeClaimTemplates:
- metadata:
name: ipfs-staging
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
- metadata:
name: ipfs-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
5. 创建service
- ipfs-headless-svc用于内部通过域名通信
- ipfs-svc用于对外暴露ui、gateway、api,并且只绑定第一个pod
apiVersion: v1
kind: Service
metadata:
name: ipfs-headless-svc
labels:
app: ipfs
spec:
ports:
- port: 8080
name: gateway
- port: 4001
name: swarm
- port: 5001
name: api
clusterIP: None
selector:
app: ipfs
---
apiVersion: v1
kind: Service
metadata:
name: ipfs-svc
labels:
app: ipfs
spec:
ports:
- port: 8080
name: gateway
- port: 4001
name: swarm
- port: 5001
name: api
selector:
app: ipfs
statefulset.kubernetes.io/pod-name: ipfs-st-0
6. 创建路由
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: ipfs
name: ui
namespace: ipfs-dev
spec:
host: ui-ipfs-dev.apps.yourdomain.com
port:
targetPort: api
to:
kind: Service
name: ipfs-svc
weight: 100
wildcardPolicy: None
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: ipfs
name: gateway
namespace: ipfs-dev
spec:
host: gateway-ipfs-dev.apps.yourdomain.com
port:
targetPort: gateway
to:
kind: Service
name: ipfs-svc
weight: 100
wildcardPolicy: None
7. peer节点配置
进入到每个容器
-
拷贝生成的swarm.key到/data/ipfs
-
删除bootstrap
ipfs bootstrap rm --all
- header头设置
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["PUT", "GET", "POST"]'
- 添加引导节点
ipfs bootstrap add /dns4/ipfs-st-0.ipfs-headless-svc.ipfs-dev.svc.cluster.local/tcp/4001/ipfs/QmVBm7L51pk41dYpBpH93Bt6YqpLBiGu8F8L2pyAYJTS4M
- 重启pod(删除pod)
8. 安装webui
1.先访问/webui,浏览器将自动重定向到ipfs/cid
2.进入第一个pod,根据cid下载相关到内容并添加到节点中
wget http://ipfs.io/api/v0/get/Qmexhq2sBHnXQbvyP2GfUdbnY7HCagH2Mw5vUNSBn2nxip
mkdir webui
tar xf Qmexhq2sBHnXQbvyP2GfUdbnY7HCagH2Mw5vUNSBn2nxip -C webui
cd webui
ipfs add -r Qmexhq2sBHnXQbvyP2GfUdbnY7HCagH2Mw5vUNSBn2nxip
ipfs pin add Qmexhq2sBHnXQbvyP2GfUdbnY7HCagH2Mw5vUNSBn2nxip
待解决问题
每扩容一个pod,需要手工配置节点:删除bootstrap、添加bootstrap