Skip to content

Instantly share code, notes, and snippets.

@gintsgints
Last active July 2, 2019 15:45
Show Gist options
  • Save gintsgints/875e8f3d5174ab847a5763a3a074aac0 to your computer and use it in GitHub Desktop.
Save gintsgints/875e8f3d5174ab847a5763a3a074aac0 to your computer and use it in GitHub Desktop.

Nano PI Docker swarm install

Nano PI as base

http://wiki.friendlyarm.com/wiki/index.php/NanoPi_NEO2#UbuntuCore_16.04

Follow instructions to download image - nanopi-neo2_sd_friendlycore-xenial_4.14_arm64_20181011.img

Write it to SD card (8 GB Min) with Win32 disk imager and put it into NanoPi. Connect to network, boot up and login with root/fa

Then follow instructions to first set up NanoPI.

https://gist.github.com/gintsgints/8d049cf122c1f2e49c5805dbce0d4653

Install docker

https://docs.docker.com/install/linux/docker-ce/ubuntu/

# Update packages first
sudo apt-get update
sudo apt-get upgrade -y
# Install/check required packages
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
# Add & verify key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
# Add Repo
sudo add-apt-repository \
   "deb [arch=arm64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
# Do install
sudo apt-get update
sudo apt-get install -y docker.io

And set docker to be started by default:

systemctl enable docker

Also if you want execute docker commands as normal user, add yourself to docker gorup (will be aiviable after restart):

sudo usermod -a -G docker username

Create node with docker-machine

Make user ass sudoer without asking password:

sudo vim /etc/sudoers
# Add this:
username ALL=(root) NOPASSWD: ALL

And then from host machine you can do:

docker-machine -D create --driver generic --generic-ip-address=192.168.0.151 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=username node1

Now you can access your remote node1 within:

eval $(docker-machine env node1)

try:

docker node ls

Switch to swarm mode

docker swarm init

Then you will get command to join your swarm from other nodes, like:

docker swarm join --token your_token_here 192.168.0.151:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions

Transfer machine

Install apps to your swarm remotely you have to move your machine configs to remote machine. You can do it with machine-share - https://github.com/bhurlow/machine-share

# Install nodejs
sudo apt-get install nodejs
sudo apt-get install npm
sudo ln -s `which nodejs` /usr/bin/node
# Install machine-share
sudo npm install -g machine-share
# Export machine
machine-export node1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment