<?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: Scott Schwab</title>
    <description>The latest articles on DEV Community by Scott Schwab (@scottschwab).</description>
    <link>https://dev.to/scottschwab</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%2F202758%2F8bde55e7-daa4-4f3a-81ae-ef929d04f448.jpeg</url>
      <title>DEV Community: Scott Schwab</title>
      <link>https://dev.to/scottschwab</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/scottschwab"/>
    <language>en</language>
    <item>
      <title>Building a Kubernetes cluster out of 3 Raspberry Pis</title>
      <dc:creator>Scott Schwab</dc:creator>
      <pubDate>Mon, 10 Feb 2020 04:57:36 +0000</pubDate>
      <link>https://dev.to/scottschwab/building-a-kubernetes-cluster-out-of-3-raspberry-pis-27go</link>
      <guid>https://dev.to/scottschwab/building-a-kubernetes-cluster-out-of-3-raspberry-pis-27go</guid>
      <description>&lt;p&gt;Based off of the great the post &lt;a href="https://kubecloud.io/setting-up-a-kubernetes-1-11-raspberry-pi-cluster-using-kubeadm-952bbda329c8"&gt;https://kubecloud.io/setting-up-a-kubernetes-1-11-raspberry-pi-cluster-using-kubeadm-952bbda329c8&lt;/a&gt;&lt;br&gt;
and the YouTube video &lt;a href="https://www.youtube.com/watch?v=2YoK4bBy3CM"&gt;https://www.youtube.com/watch?v=2YoK4bBy3CM&lt;/a&gt;, for networking.&lt;/p&gt;
&lt;h2&gt;
  
  
  Hardware
&lt;/h2&gt;

&lt;p&gt;For the hardware&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.microcenter.com/product/609038/raspberry-pi-4-model-b---4gb-ddr4"&gt;3 RaspberryPi 4B, with 4GB RAM&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/gp/product/B07XRF4GRS/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&amp;amp;psc=1"&gt;Dorhea Raspberry Pi 4 B Case&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/gp/product/B07YR6M6F6/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&amp;amp;psc=1"&gt;A set of aluminum heatsinks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.microcenter.com/product/414582/tp-link-tl-sg108-8-port-10-100-1000-gigabit-desktop-switch"&gt;TP-LINK 8-port Gigabit Desktop Switch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/gp/product/B0721RFHT8/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&amp;amp;psc=1"&gt;A set of Cat6 Ethernet Cables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/gp/product/B01N32UM0Q/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&amp;amp;psc=1"&gt;Set of USB C charging cables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.com/gp/product/B00P933OJC/ref=ppx_yo_dt_b_asin_title_o01_s01?ie=UTF8&amp;amp;psc=1"&gt;Anker 60W 6-Port USB wall charger&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/gp/product/B07NP96DX5/ref=ppx_yo_dt_b_asin_title_o01_s02?ie=UTF8&amp;amp;psc=1"&gt;Set of Samsung 32GB micro SDHC cards&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Setting up the Raspberry Pis
&lt;/h2&gt;

&lt;p&gt;In this setup I am using 3 Raspberry Pi 4s, but other versions of the Pis should work as well.  To set them up:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Flash 3 SD Cards with the latest Raspian images.&lt;/li&gt;
&lt;li&gt;After flashing, remount the SD Card and in the /boot directory of the SD Card add an empty file named &lt;code&gt;ssh&lt;/code&gt;.  This will enable ssh on the Pi running off of this image.
&lt;/li&gt;
&lt;li&gt;Unmount the SD Card and insert it into a Pi.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Network and Kubeadm Installs
&lt;/h2&gt;

&lt;p&gt;Connect the Pis to a switch and the switch to your local network.  When the Pi boots, it can be reached at &lt;code&gt;ssh pi@raspberrypi.local&lt;/code&gt; with the password &lt;code&gt;raspberry&lt;/code&gt;.  Now since all three Pis start with the same DNS name, I would power on one, updated its network settings, and rebooted it.  After it is up and running with it's own DNS name, I could then plugin the next Pi and repeated the process.  Stepping through Pis this way keeps only one Pi with the domain name raspberrypi.local on the network at a time.&lt;/p&gt;
&lt;h3&gt;
  
  
  Network Setup
&lt;/h3&gt;

&lt;p&gt;We start by updating the Pi's &lt;code&gt;/etc/hosts&lt;/code&gt; and &lt;code&gt;/etc/dhcpcd.conf&lt;/code&gt;.  To do this, I used the script below, passing in the hostname and last octet of the IP address as the parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh
#
# set_host.sh
#
# Usage: ./set_host.sh &amp;lt;hostname&amp;gt; &amp;lt;last octet&amp;gt;
#  ./set_host.sh k8master 223
# for example
#

hostname=$1
ip=$2
dns=192.168.1.1

sudo -- sh -c "cat &amp;lt;&amp;lt;EOT &amp;gt;&amp;gt; /etc/hosts
192.168.1.223   k8master
192.168.1.224   k8worker1
192.168.1.225   k8worker2
EOT"


sudo cat &amp;lt;&amp;lt;EOT &amp;gt;&amp;gt; /etc/dhcpcd.conf
interface eth0
static ip_address=192.168.1.${ip}/24
static routers=${dns}
static domain_name_servers=${dns}
EOT

sudo sed -i s/raspberrypi/${hostname}/g /etc/hosts
sudo hostnamectl --transient set-hostname ${hostname}
sudo hostnamectl --static set-hostname ${hostname}
sudo hostnamectl --pretty set-hostname ${hostname}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After running the script, be sure to &lt;strong&gt;reboot&lt;/strong&gt; the Pi, for the network changes to take effect.&lt;/p&gt;

&lt;h3&gt;
  
  
  Software Install
&lt;/h3&gt;

&lt;p&gt;After the network on the Pi setup, installation of docker and Kubernetes software is next.  Again a shell script was used for installation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/sh
#
# Usage: ./set_kube.sh
# InstalLs the docker and kubernetes software
#

# Install Docker
curl -sSL get.docker.com | sh &amp;amp;&amp;amp; \
sudo usermod pi -aG docker

# Disable Swap
sudo dphys-swapfile swapoff &amp;amp;&amp;amp; \
sudo dphys-swapfile uninstall &amp;amp;&amp;amp; \
sudo update-rc.d dphys-swapfile remove
echo Adding " cgroup_enable=cpuset cgroup_enable=memory" to /boot/cmdline.txt
sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt
orig="$(head -n1 /boot/cmdline.txt) cgroup_enable=cpuset cgroup_enable=memory"
echo $orig | sudo tee /boot/cmdline.txt

# Add repo list and install kubeadm
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - &amp;amp;&amp;amp; \
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list &amp;amp;&amp;amp; \
sudo apt-get update -q &amp;amp;&amp;amp; \
sudo apt-get install -qy kubeadm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Start up
&lt;/h2&gt;

&lt;p&gt;Only on your master node, run kubeadm init, and include the pod-network-cdir parameter, needed for the flannel networking.  The pod-network-cidr needs to be different then the one for your node's network.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo kubeadm init --pod-network-cidr=10.244.0.0/16
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As kubeadm runs, it will print out needed information.&lt;/p&gt;

&lt;p&gt;Setup for kubectl:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Connection command for worker nodes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  kubeadm join 192.168.1.223:6443 --token k3mpju.xxxxxxxloccv878b \
    --discovery-token-ca-cert-hash sha256:63225cc63b7189c3cc4c091fff07cad4bxxxxxxxxxx2846f36cd00543ad6f54c
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Before adding worker nodes&lt;/em&gt; install the Flannel network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Flannel network
&lt;/h2&gt;

&lt;p&gt;On the master node, run the command below to install networking.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding Worker Nodes
&lt;/h2&gt;

&lt;p&gt;Log into each worker node, and using the connection command displayed when the master's kubeadm was executed, add the workers to the cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo kubeadm join 192.168.1.223:6443 --token k3mpju.xxxxxxxloccv878b \
    --discovery-token-ca-cert-hash sha256:63225cc63b7189c3cc4c091fff07cad4bxxxxxxxxxx2846f36cd00543ad6f54c
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you lose the join token, you can recreate it with these commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubeadm token generate
kubeadm token create &amp;lt;generated token&amp;gt; --print-join-command --ttl=0

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



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

&lt;p&gt;At the end of this process, you should have three nodes Ready along with set of pods ready as well.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>raspberrypi</category>
      <category>flannel</category>
    </item>
  </channel>
</rss>
