通过Helm在Kubernetes集群上安装IPFS
Helm (https://helm.sh/) 是用于Kubernetes的应用包管理程序,可以按照定义来安装、启动、停止、删除由多个Docker和Pod组合的服务应用,而且具有回滚等功能。
- Helm的后台服务为Tiller,包描述文件称为Chart,是yaml格式,与Docker Compose有类似之处,但可选参数更多。
- Helm的Chart可以保存在本地文件、本地Repo、Monocular或者Github等各种文件服务系统之中。
- Helm安装方法,参见:https://my.oschina.net/u/2306127/blog/1619818。
IPFS (http://ipfs.io/)可以通过Helm在Kubernetes集群上快速部署和方便地管理。
- IPFS在Kubernetes部署的服务开放,https://my.oschina.net/u/2306127/blog/1933999
IPFS其它运行方式还有:
- 可以直接命令行在主机里运行。
- 通过Docker命令行安装运行(https://my.oschina.net/u/2306127/blog/1613968)。
- 通过Docker Compose文件来运行,以及运行于Swarm模式下。
- 通过Kubernetes的Pod描述yml文件安装(https://my.oschina.net/u/2306127/blog/1621664)。
这里描述基于Helm的IPFS安装步骤。
- 此处的方法在Docker for Mac Edge 18.02 mac53上运行通过。
1、复制Helm Charts库
git clone https://github.com/openthings/zhelm-charts.git
因为我们要进行一些修改,将stable/ipfs复制到自己的目录,如:zolo/ipfs。上面的库中已包含这个目录。因为Kubernetes官方Chart的ipfs版本较低,我们将其改为最新的0.4.13版本(注意values.yaml和Chart.yaml两个文件里的修改部分)。
2、安装IPFS Chart
进入目录 zolo/ipfs,运行:
helm install --name ipfs-node .
输出如下:
NAME: ipfs-node
LAST DEPLOYED: Tue Feb 13 21:24:04 2018
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ipfs-node-ipfs ClusterIP 10.98.146.104 <none> 5001/TCP,8080/TCP 0s
==> v1beta1/StatefulSet
NAME DESIRED CURRENT AGE
ipfs-node-ipfs 1 1 0s
NOTES:
You have successfully installed IPFS in your kubernetes cluster!
You can access the IPFS API from inside your cluster by connecting to port 5001 on
ipfs-node-ipfs.default
You can also connect to port 8080 on the same hostname for talking to the IPFS Gateway.
If you want to connect to it from your local computer, you can find a URL to connect with the
following (for the gateway service):
export POD_NAME=$(kubectl get pods --namespace default -l "app=ipfs,release=ipfs-node" -o jsonpath="{.items[0].metadata.name}")
echo "Use the API Gateway by accessing http://localhost:8080/ipfs/<IPFS-HASH>"
kubectl --namespace default port-forward $POD_NAME 8080:8080
3、查看运行状态
kubectl get pod
输出如下:
NAME READY STATUS RESTARTS AGE
ipfs-node-ipfs-0 1/1 Running 0 1m
peddling-kitten-mongodb-55d9b47bb9-gb7tp 1/1 Running 0 2d
peddling-kitten-monocular-api-6744c4cc66-gcsrs 1/1 Running 3 2d
peddling-kitten-monocular-api-6744c4cc66-gfz5t 1/1 Running 1 2d
peddling-kitten-monocular-prerender-5fcbd99b78-h2t6v 1/1 Running 0 2d
peddling-kitten-monocular-ui-7977d5c949-c47sj 1/1 Running 0 2d
peddling-kitten-monocular-ui-7977d5c949-kchp4 1/1 Running 0 2d
wondering-yak-nginx-ingress-controller-7cd79f85cd-88z2b 1/1 Running 0 2d
wondering-yak-nginx-ingress-default-backend-55755b66b4-hwd4z 1/1 Running 0 2d
可以看到ipfs-node的Pod已经运行起来了(如果第一次运行,需要下载ipfs的Docker镜像,需要耐心等待STATUS变为Running,再进行后续操作)。
4、映射服务端口
这里使用Kubernetes的port-forward方法映射服务端口到主机端口,但每次需哟啊运行一个服务。更多的方法参见:
- IPFS在Kubernetes部署的服务开放,https://my.oschina.net/u/2306127/blog/1933999
现在按照提示,获取信息,映射服务端口:
export POD_NAME=$(kubectl get pods --namespace default -l "app=ipfs,release=ipfs-node" -o jsonpath="{.items[0].metadata.name}")
echo "Use the API Gateway by accessing http://localhost:8080/ipfs/<IPFS-HASH>"
kubectl --namespace default port-forward $POD_NAME 8080:8080
- 注意,除了上面之外,我们还需要映射5001端口以便于本地管理,因此,最后一行改为:
kubectl --namespace default port-forward $POD_NAME 8080:8080 5001:5001
保持这个命令一直运行,打开浏览器,输入:http://127.0.0.1:5001/webui,可以看到IPFS的本地管理界面。可以在里面上传文件,然后使用:http://127.0.0.1:8080/ipfs/<IPFS-HASH>的方式访问。鼠标右键单击Files里所上传的文件也可以获得该文件资源的HashCode值。

使用其它的Kubenetes管理工具(如Kubernetes Dashboard)也可以看到部署的pod服务。
5、删除ipfs-node服务
如果不再需要了,可以一行命令删除之。
#删除运行的服务
helm delete ipfs-node
#彻底删除Helm部署,重新安装
helm del --purge ipfs-node
更多参考
- IPFS 命令大全,https://my.oschina.net/u/2306127/blog/1608391
- IPFS 浏览器插件,https://my.oschina.net/u/2306127/blog/1610793
来源:oschina
链接:https://my.oschina.net/u/2306127/blog/1621893