[advanced] Running masternodes in containers

ender_x

New Member
Masternode Owner/Operator
Mar 31, 2017
3
0
1
39
Guide to host a masternode on hyper.sh for ~$12USD/Month

To use this guide you will need the following pieces of information:
  • hyper.sh account and download the command line utility(hyper)
  • masternode private key
  • exactly 1000 dash sitting in a new address with no other tx's in it.
  • knowledge of how to remotely start a masternode.
from a shell run the following, filling in the blanks as needed:
Code:
#one time step: create a "floating ip" for a $1USD/month (this can be reused if you ever delete your node and recreate)
hyper fip allocate
hyper fip ls
ip= #the ip address you were allocated from hyper
key= #your masternode private key. (not your collateral private key)
nodename= #whatever you would like to name this container.

hyper create --size m1 -e MNIP=${ip} -e MNKEY=${key} --name "${nodename}" -P -t --restart always yourdockerhub/imagename:latest
hyper start "${nodename}"
hyper fip attach ${ip%:*} "${nodename}"

#watch the logs of your newly created container. hit ctrl-c when you've seen enough.
hyper logs -f "${nodename}"

#run commands within your container (for example..)
hyper exec -it "${nodename}" dash-cli mnsync status
hyper exec -it "${nodename}" bash
after mnsync status shows your node is synced.. remotely start your masternode(eg run `masternode start-missing` using dash-cli or the wallet console.)

Guide to host a masternode in a Kubernetes cluster
(like Google container engine or something else?)


To use this guide you will need the following pieces of information:
  • access to a kubernetes cluster with kubectl configured.
  • masternode private key
  • exactly 1000 dash sitting in a new address with no other tx's in it.
  • knowledge of how to remotely start a masternode.
Code:
#example by brute force.
nodename= #whatever you would like to call your node(no spaces or crazy chars)
key= #masternode private key (not collateral key)

cat << EOF |kubectl create -f -
kind: Service
apiVersion: v1
metadata:
 labels:
   name: $nodename
 name: $nodename
spec:
 type: LoadBalancer
 ports:
 - port: 9999
   protocol: TCP
   name: $nodename
 selector:
   name: $nodename
EOF

#depending on your provider.. the external ip may not be ready yet.. but the goal is to collect it from this output.
kubectl get service -o yaml

ip= #what you found.

cat << EOF |kubectl create -f -
kind: ReplicationController
apiVersion: v1
metadata:
 name: $nodename
 labels:
   name: $nodename
spec:
 replicas: 1
 selector:
   name: $nodename
 template:
   metadata:
     labels:
       name: $nodename
   spec:
     containers:
     - image: yourdockerhub/imagename:latest
       imagePullPolicy: Always
       name: $nodename
       ports:
       - containerPort: 9999
         protocol: TCP
       env:
         - name: MNKEY
           value: $key
         - name: MNIP
           value: $ip
     restartPolicy: Always
EOF

kubectl get pods
kubectl logs -f #podnamehere

#check mnsync status:
kubectl exec -it #podnamehere dash-cli mnsync status

#run a shell inside container..
kubectl exec -it #podnamehere bash
after mnsync status shows 999 goodness.. remotely start your masternode.


Dockerfile used by both examples:
Code:
# Dockerfile for Dashd
FROM debian:jessie
MAINTAINER your mom
LABEL description="dockerized dashd for running masternodes"

RUN apt-get update \
 && apt-get install -y curl iptables git python-virtualenv \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV DASH_DOWNLOAD_URL  github.com/dashpay/dash/releases/download/v0.12.1.4/dashcore-0.12.1.4-linux64.tar.gz
RUN cd /tmp \
 && curl -sSL "$DASH_DOWNLOAD_URL" -o dash.tgz "$DASH_DOWNLOAD_URL.asc" -o dash.tgz.asc \
 && echo "AF1AE13F33D06F487F23DC814B88269ABD8DF332:6:"|gpg --import-ownertrust \
 && gpg --keyserver pgp.mit.edu --recv-keys 0x4B88269ABD8DF332 \
 && gpg --verify dash.tgz.asc dash.tgz \
 && tar xzf dash.tgz --no-anchored dashd dash-cli --transform='s/.*\///' \
 && mv dashd dash-cli /usr/bin/ \
 && rm -rf dash* \
 && echo "#""!/bin/bash\n/usr/bin/dashd -datadir=/dash \"\[email protected]\"" > /usr/local/bin/dashd \
 && echo "#""!/bin/bash\n/usr/bin/dash-cli -datadir=/dash \"\[email protected]\"" > /usr/local/bin/dash-cli \
 && chmod a+x /usr/local/bin/dashd /usr/local/bin/dash-cli /usr/bin/dashd /usr/bin/dash-cli


ENV HOME /dash
RUN /usr/sbin/useradd -s /bin/bash -m -d /dash dash \
 && chown dash:dash -R /dash
ADD dash.conf /dash/dash.conf
RUN chown dash:dash -R /dash
USER dash

RUN cd dash \
 && git clone git://github.com/dashpay/sentinel \
 && cd sentinel \
 && virtualenv venv \
 && venv/bin/pip install -r requirements.txt \
 && ln -s ~ ~/.dashcore

#fetch to semi recent block
#warning! makes for large image, but fast startup times.
ENV BLOCKS 644184
RUN dashd & sleep 10;echo "syncing blocks(this will take a while)"; while [ ${t:-0} -lt $BLOCKS ];do t=$(dash-cli getinfo|grep blocks); t=${t##* };t=${t%,};echo -n ${t:-0}" "; sleep 10;done;dash-cli getinfo;dash-cli stop;sleep 10

RUN rm /dash/wallet.dat

EXPOSE 9999

WORKDIR /dash
CMD echo externalip=${MNIP%:*} >> /dash/dash.conf; echo masternodeprivkey=$MNKEY >> /dash/dash.conf; while sleep 60;do sentinel/venv/bin/python sentinel/bin/sentinel.py;done& exec dashd -printtoconsole
note you'll also need to provide a dash.conf stub.
sample:
Code:
#daemon=1 never set this.. cause containers.
logtimestamps=1
maxconnections=256
masternode=1
#addnode=some node you like
#addnode=some other node you like
keypool=1
 
Last edited:

camosoul

Grizzled Member
Sep 19, 2014
2,263
1,130
1,183
"$12USD/Month"

Not to rain on your parade, but that sounds kinda expensive...
 

ender_x

New Member
Masternode Owner/Operator
Mar 31, 2017
3
0
1
39
I'm actually doing compiling and using bootstrap stuff now.. thanks to UdjinM6. I also have a testnet flag if anyone is interested in that stuff I can update this guide. Or if you have any requests/suggestions surrounding containerization I'd love to hear them.
 

Figlmüller

Member
Sep 2, 2014
85
45
58
Vienna, Austria
"$12USD/Month"

Not to rain on your parade, but that sounds kinda expensive...
Only if you use a container solution as a service. You can set up a container solution, for example a docker swarm yourself on dedicated servers. Together with a private registry, monitoring and fault tolerancy you can easily get down to 2.5 EUR/2,98 USD per Node per month (assuming the machines are working to capacity, else you will end up with one 40USD box running one node only). Also you will have to maintain that stuff and keep it safe. This is something I do in my coffee breaks, but other people may need to put a lot more effort into this (at least an hour a day).
 
  • Like
Reactions: stan.distortion