<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mikts</title>
    <description>The latest articles on DEV Community by Mikts (@mikts).</description>
    <link>https://dev.to/mikts</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F215663%2F5d6b9ba5-2f82-4360-938f-f212469f945d.jpeg</url>
      <title>DEV Community: Mikts</title>
      <link>https://dev.to/mikts</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mikts"/>
    <language>en</language>
    <item>
      <title>How to prepare Raspberry Pi for Docker Swarm</title>
      <dc:creator>Mikts</dc:creator>
      <pubDate>Thu, 30 Apr 2020 15:36:20 +0000</pubDate>
      <link>https://dev.to/mikts/how-to-prepare-raspberry-pi-for-docker-swarm-12k1</link>
      <guid>https://dev.to/mikts/how-to-prepare-raspberry-pi-for-docker-swarm-12k1</guid>
      <description>&lt;h2&gt;
  
  
  Swarm Cluster
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;With the release of the &lt;strong&gt;Raspberry Pi 4B&lt;/strong&gt; using the board to run container orchestrators&lt;br&gt;
like &lt;strong&gt;Kubernetes&lt;/strong&gt; and &lt;strong&gt;Docker Swarm&lt;/strong&gt; is a viable option both a learning platform but also&lt;br&gt;
as a low power development lab. In this series we will build a Swarm cluster on those little boards.&lt;/p&gt;
&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;x3 Raspberry Pi 4B&lt;/li&gt;
&lt;li&gt;x3 SD Cards&lt;/li&gt;
&lt;li&gt;x3 External Storage &lt;strong&gt;&lt;em&gt;optional&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  OS Prepare
&lt;/h3&gt;

&lt;p&gt;We will use the &lt;strong&gt;hypriotOS&lt;/strong&gt; a lightweight arm distribution optimized for docker engine with some cool&lt;br&gt;
features like cloud-init and a nice flash tool which we will use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-LO&lt;/span&gt; https://github.com/hypriot/flash/releases/download/2.5.0/flash
&lt;span class="nb"&gt;chmod&lt;/span&gt; +x flash
&lt;span class="nb"&gt;sudo mv &lt;/span&gt;flash /usr/local/bin/flash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then download the latest hypriot.img&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget https://github.com/hypriot/image-builder-rpi/releases/tag/v1.11.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Cloud-Init
&lt;/h4&gt;

&lt;p&gt;A convenient configuration tool mostly used in cloud environment.&lt;br&gt;&lt;br&gt;
Below is a template you can find the vars you should change with &lt;code&gt;"{{ var_name }}"&lt;/code&gt; useful for ansible 😉&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;hostname&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;your_hostname}}&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
&lt;span class="na"&gt;manage_etc_hosts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;

&lt;span class="na"&gt;users&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;your_user&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;}}&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
    &lt;span class="na"&gt;gecos&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Swarm&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Admin"&lt;/span&gt;
    &lt;span class="na"&gt;sudo&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ALL=(ALL) NOPASSWD:ALL&lt;/span&gt;
    &lt;span class="na"&gt;shell&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/bin/bash&lt;/span&gt;
    &lt;span class="na"&gt;groups&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;users,docker,video,input&lt;/span&gt;
    &lt;span class="na"&gt;lock_passwd&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
    &lt;span class="na"&gt;ssh_authorized_keys&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;ssh-rsa "{{ your_pub_key }}"&lt;/span&gt;

&lt;span class="na"&gt;runcmd&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# Pickup the hostname changes&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;systemctl&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;restart&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;avahi-daemon'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flash the img to each sd card better to use different hostname for each&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;flash &lt;span class="nt"&gt;-u&lt;/span&gt; cloud-init.yml hypriotos-rpi-v1.11.5.img.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose your sd card in the prompt and let it flash it!&lt;br&gt;&lt;br&gt;
ssh to your pi with your rsa-key and you are ready for the final configurations.&lt;/p&gt;
&lt;h4&gt;
  
  
  Docker Engine optimize
&lt;/h4&gt;

&lt;p&gt;Although you can run everything in the sd card and work perfectly fine the docker-engine&lt;br&gt;
performs some heavy writing and &lt;em&gt;sd cards are slow bricks&lt;/em&gt; so we will use the external drives&lt;br&gt;
to mount the &lt;code&gt;/var/lib/docker&lt;/code&gt; path to them and improve the performance and our sd cards lifetime.&lt;/p&gt;

&lt;p&gt;Find your disk with &lt;code&gt;lsblk&lt;/code&gt; and modify your &lt;code&gt;/etc/fstab&lt;/code&gt; file similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; /etc/fstab

/dev/sda1 /var/lib/docker ext4 defaults,auto,nofail,noatime 0 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now all your docker related data will be stored in the external disk improving the performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Swarm
&lt;/h3&gt;

&lt;p&gt;It's clear Kubernetes won the orchestrator war and is a much for feature complete proposition but also&lt;br&gt;
a more complex one. Swarm is much easier to begin especially when you are just starting to learn about&lt;br&gt;
Docker and Container Orchestration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's it your raspberries are ready with a lightweight os with docker-runtime ready to create a small&lt;br&gt;
cluster. We will continue the series with creating the cluster start running swarm &lt;code&gt;services&lt;/code&gt; and &lt;code&gt;stacks&lt;/code&gt;&lt;br&gt;
on it.&lt;/p&gt;

&lt;p&gt;Check how to deploy your Docker Swarm &lt;a href="https://clusterstacks.codes/how-to-deploy-docker-swarm-in-raspberry-pi-cluster/"&gt;&lt;strong&gt;&lt;em&gt;How to deploy Docker Swarm in Raspberry Pi Cluster&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>raspberrypi</category>
    </item>
  </channel>
</rss>
