Code Monkey home page Code Monkey logo

devops-rasp-kube's Introduction

Kuberenetes cluster on RaspberryPi the DevOps way

Etcher This repo installs K3S kubernetes cluster on 3 raspberry pi computers. I used recent raspberry pi model (4B) for this demo but you can install it on almost all modern raspberry pi models. (RPi 2,3 and 4)

We'd like to use DevOps/Cloud tools such as docker, packer and ansible to make it cool like we are running the cluster on our own home private cloud ;-)

Build the raspberry pi packer image

We're going to build rapsberry pi images by packer using packer-builder-arm-image repo.

Docker

Run the docker container to build the raspberry pi packer image:

cd packer/ && mkdir packer_cache output-arm-image

docker run \
  --rm \
  --privileged \
  -v ${PWD}:/build:rw \
  -v ${HOME}/.ssh:/build/.ssh:ro \
  -v ${PWD}/packer_cache:/build/packer_cache \
  -v ${PWD}/output-arm-image:/build/output-arm-image \
  -e RPI_HOSTNAME=raspberrypi.local \
  -e RPI_DHCP_DISABLE=true \
  -e RPI_INTERFACE=eth0 \
  -e RPI_IP_ADDRESS=192.168.1.1/24 \
  -e RPI_GATEWAY=192.168.1.1 \
  -e RPI_DNS_SERVERS=8.8.8.8 \
  -e UPDATE_PKGS=false \
  pyguy/packer-builder-arm build raspbian_kube.json

The image will be placed on output-arm-image directory.

Notes:

  • You can use the following custom environment variables in the docker run command:

    Env name Env value Example Required
    RPI_HOSTNAME hostname raspberrypi.local Yes
    RPI_DHCP_DISABLE true/false true No
    RPI_INTERFACE network interface eth0 No
    RPI_IP_ADDRESS ip address with cidr 192.168.1.1/24 No
    RPI_GATEWAY router gateway 192.168.1.1 No
    RPI_DNS_SERVERS dns servers 8.8.8.8 No
  • Your default public key will be added to the image, to add any other custom public keys to the image add the following variable to the following command: -var ssh_key_src=<custom public key file>

Setup the SD card

The following section is going to be used for all the nodes in the cluser. So let's do it one by one:

Flashing the SD card

We use Etcher for flashing the SD-cards. Just select the image file we built on output-arm-image/<hostname>.img, insert your SD-card, select the drive, and click “Flash!”. That's it!

Etcher

Run K3S cluster with ansible

We use ansible roles for setting up the cluster.

Make inventory file

Copy the sample inventory file: cp inventory/hosts.ini.sample inventory/hosts.ini

and make sure that the inventory file is updated with your own hosts.

setup cluster

Run the following ansible playbook command:

ansible-plapybook -i inventory/hosts.ini site.yml

delete the cluster

Run the following ansible playbook command:

ansible-plapybook -i inventory/hosts.ini reset.yml

Provision k8s applications

Run the following command to install required collections:

ansible-galaxy install -r requirements.yml

Run the following ansible playbook command:

ansible-plapybook -i inventory/hosts.ini deploy.yml

devops-rasp-kube's People

Contributors

pyguy avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.