Create IPFS Swarm

IPFS Swarm of nodes are ipfs nodes that connect to each others but don't share the same pin set like ipfs cluster.

# swarm.yaml
kind: Swarm
name: sample-swarm
- name: node-1
id: "12D3KooWN16bUqeedKUQHXtHJjUT1oEyFBr6YnKQ7B4LSTAnbTye"
privateKey: "CAESQMbyIcsxBsn8kIk9sbL2NdVwSBf/Uj9BOA5KbXnrgmNHtQwF4rgzxd2XXpmdhIBxnlghaYVNBLzcRj2f6PCKnD0="
- server
- flatfs
- name: node-2
id: "12D3KooWCHgCddSVSLigTSyUATtq2SicYSSVPTn9xMRFv49D4Gwd"
privateKey: "CAESQF+tQn8qXgNR9ssoBV7xjPrgGB3dAgp5/M8VNNQjr7B5JLZx9nOY/4bllbCbc2Cq6xB9vVC43LuF8nIcitLVDvQ="
- lowpower

Using kotal you can create ipfs swarm simply by deploying this swarm mainfest.

$ kubectl apply -f swarm.yaml

Kotal will create an ipfs swarm of 2 nodes, the first node node-1 will use 2 ipfs configuration profiles server and flatfs. the second node node-2 wil use only lowpower ipfs configuration profile.

As you can see from the example swarm above, each node starts with a pre-generated private key privateKey using ipfs-key tool and indentity id to make it easy to establish network between the nodes.

After applying the swarm manifest, Kotal will create the swarm deployments, volumes, services ... etc for you. Let's check the swarm's pods

$ kubectl get pods

you will get output similar to this

pod/sample-swarm-node-1 1/1 Running 0 10s
pod/sample-swarm-node-2 1/1 Running 0 10s

Check the logs of node-1

$ kubectl logs <node-1 pod name>

You will get ouput similar to

Initializing daemon...
go-ipfs version: 0.6.0-d6e036a
Repo version: 10
System version: amd64/linux
Golang version: go1.14.2
Swarm listening on /ip4/
Swarm listening on /ip4/
Swarm listening on /ip4/
Swarm listening on /ip4/
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /ip6/::1/udp/4001/quic
Swarm listening on /p2p-circuit
Swarm announcing /ip4/
Swarm announcing /ip4/
Swarm announcing /ip6/::1/tcp/4001
Swarm announcing /ip6/::1/udp/4001/quic
API server listening on /ip4/
Gateway (readonly) server listening on /ip4/
Daemon is ready

Let's send an API call to node-1, but first lets forward hocalhost:5001 calls to node-1 pod

$ kubectl port-forward <node-1 pod name> 5001
Forwarding from -> 5001
Forwarding from [::1]:5001 -> 5001

In another terminal window, send get bootstrap peers API call

curl -X POST

You'll get result similar to this

"Peers": [

You can view the ipfs web interface of node-1 by visiting http://localhost:5001/webui in your browser.

Finally you can delete the swarm and all its resources by

kubectl delete -f swarm.yaml

and kubernetes garbage collector will delete all resources created by swarm controller.