Skip to content

spaulg/raspberrypi-k8s-the-hard-way

Repository files navigation

Raspberry PI k8s Ansible playbook

Master node

SD Card Prep

Format the micro sd card with two FAT32 partitions.

I use FAT32 as the root partition as Mac does not support ext4, but we reformat that partition later anyway. This just means it sets up the partition table correctly.

diskutil partitionDisk disk2 MBR \
  "MS-DOS FAT32" RPIBOOT 256MB \
  "MS-DOS FAT32" RPIROOT R
  1. Uncompress the Alpine tar.gz contents directly in to the boot partition by running:
cd /Volumes/RPIBOOT
tar -xzf ~/Downloads/alpine.tar.gz
  1. Eject the sd card
  2. Move the sd card in to the RPI
  3. Turn on the PI

Diskless installation

  1. Login as root. No password is required.
  2. Run setup-alpine
    1. Select the keyboard layout: gb
    2. Select the keyboard variant: gb-extd
    3. Enter hostname. e.g. pimaster
    4. Choose eth0 as the network interface
    5. Choose dhcp sa the IP address
    6. Skip setup of the wifi interface by entering "done"
    7. Skip manual configuration by entering "n"
    8. Enter a new root password
    9. Confirm the new root password
    10. Enter the timezone: Europe/London
    11. Select none as http/ftp proxy
    12. Accept chrony as the ntp client
    13. Enter 1 (dl-cdn.alpinelinux.org) as the mirror server
    14. Accept openssh as the SSH server
    15. Accept none as disk to use
    16. Accept the sd card as location to store configs
    17. Accept the sd card as the apk cache directory
  3. Run
apk add e2fsprogs dosfstools vim
lbu commid -d
reboot

Converting to disk installation

  1. Login as root, using the new password used during installation
  2. Run
# Prepare the root disk
mkfs.ext4 /dev/mmcblk0p2

# Prepare the root mount
mkdir /stage
mount /dev/mmcblk0p2 /stage

# Prepare the boot mount
mkdir /stage/boot
mount -o remount,rw /meda/mmcblk0p1
mount --bind /media/mmcblk0p1 /stage/boot

# Install Alpine to the root disk
setup-disk -o /media/mmcblk0p1/$(hostname).apkovl.tar.gz /stage

# [optional] Remove unnecessary devices from fstab on new disk
sed -i '/cdrom/d' /stage/etc/fstab
sed -i '/usbdisk/d' /stage/etc/fstab
sed -i '/floppy/d' /stage/etc/fstab

reboot

Worker nodes

Alpine Linux installation

SD Card Prep

  1. Format the micro sd card with a single FAT32 partition, labelling it RPIBOOT.

As we'll be using a separate mSATA drive over USB, the entire sd card is used for boot and thus only a single partition is formatted.

diskutil partitionDisk disk2 MBR \
  "MS-DOS FAT32" RPIBOOT R
  1. Uncompress the Alpine tar.gz contents directly in to the partition by running:
cd /Volumes/RPIBOOT
tar -xzf ~/Downloads/alpine.tar.gz
  1. Eject the sd card
  2. Move the sd card in to the RPI
  3. Turn on the PI

Diskless installation

  1. Login as root. No password is required.
  2. Run setup-alpine
    1. Select the keyboard layout: gb
    2. Select the keyboard variant: gb-extd
    3. Enter hostname. e.g. pi1
    4. Choose eth0 as the network interface
    5. Choose dhcp sa the IP address
    6. Skip setup of the wifi interface by entering "done"
    7. Skip manual configuration by entering "n"
    8. Enter a new root password
    9. Confirm the new root password
    10. Enter the timezone: Europe/London
    11. Select none as http/ftp proxy
    12. Accept chrony as the ntp client
    13. Enter 1 (dl-cdn.alpinelinux.org) as the mirror server
    14. Accept openssh as the SSH server
    15. Accept none as disk to use
    16. Accept the sd card as location to store configs
    17. Accept the sd card as the apk cache directory
  3. Run
apk add e2fsprogs dosfstools vim
lbu commid -d
reboot

Converting to disk installation

  1. Login as root, using the new password used during installation
  2. If no partition table has been created for the mSATA drive, run:
fdisk /dev/sda
1. Type n
2. Type p
3. Type 1
4. Accept the start position
5. Accept the end position
6. Type w
  1. Run
# Prepare the root disk
mkfs.ext4 /dev/sda1

# Prepare the root mount
mkdir /stage
mount /dev/sda1 /stage

# Prepare the boot mount
mkdir /stage/boot
mount -o remount,rw /meda/mmcblk0p1
mount --bind /media/mmcblk0p1 /stage/boot

# Install Alpine to the root disk
setup-disk -o /media/mmcblk0p1/$(hostname).apkovl.tar.gz /stage

# [optional] Remove unnecessary devices from fstab on new disk
sed -i '/cdrom/d' /stage/etc/fstab
sed -i '/usbdisk/d' /stage/etc/fstab
sed -i '/floppy/d' /stage/etc/fstab

reboot

Post installation

  1. Run
# Remove the local apk repository setup during diskless install
sed -i '/mmcblk0p1/d' /etc/apk/repositories

# Cleanup the boot partition of files no longer required
rm -rf /boot/apks /boot/cache /boot/boot /boot/overlays /boot/*.apkovl.tar.gz

# Setup an admin user with sudo access
apk add sudo
adduser -g "<Users name>" -G wheel <username>

# Add Python (for running Ansible)
apk add python3
  1. Run visudo and uncomment the line:
%wheel ALL=(ALL) NOPASSWD: ALL
  1. Run
apk update
apk upgrade
reboot

Ansible

Setup

Create the inventory file

cp hosts.ini.example hosts.ini

Modify the hosts.ini file, listing hosts that should be managed.

Provisioning workers

ansible-playbook --limit workers master.yml

About

Raspberry PI k8s The Hard Way

Resources

Stars

Watchers

Forks

Contributors