Raspberry pi 4B kubernetes cluster

I love decentralized computing. It’s beautiful. Just add a node to your cluster if you need more power! Just that. Restart the pods with no downtime, horizontal pod autoscaler…

To create a cluster, we can do it with services provided by google, amaz…


This content originally appeared on DEV Community and was authored by NULLX

I love decentralized computing. It’s beautiful. Just add a node to your cluster if you need more power! Just that. Restart the pods with no downtime, horizontal pod autoscaler...

To create a cluster, we can do it with services provided by google, amazon… or just manually installing it in each node.

I prefer to create my own mini cluster. My cluster is made of 6 raspberry pi 4B (4GB RAM each) and has it's own name: clusperry ⚡️

Cluster preview

I created a simple gui tool to generate the linux images to flash into the mini-SD cards with the initial cloudconfig. You can check it here: https://sh.nullx.me/clusperry-installer.

Nodes setup

Download the release from https://github.com/nullxx/clusperry-installer/releases/ (its currently only compiled for macOS)

1. Select the nodes operating system

SELECT OS

2. Configure each node with your configuration:

  • IP
  • WIFI (or ethernet)
  • hostname
  • SSH keys CONFIGURE NODES

3. Download OS images

Download

4. Write images

Write images

5. Open generated images

Open generated images

Installl kubernetes with k3s

For this I will use ansible. It makes it easier to do all the install work.
I will use the following repo: https://github.com/k3s-io/k3s-ansible

Clone the repo

git clone https://github.com/k3s-io/k3s-ansible.git

Get into the cloned repo

cd k3s-ansible

Create our inventory from the sample

cp -R inventory/sample inventory/my-cluster

Edit inventory/my-cluster/hosts.ini

nano inventory/my-cluster/hosts.ini
[master]
192.168.1.100

[node]
192.168.1.101
192.168.1.102
192.168.1.103
192.168.1.104
192.168.1.105

[k3s_cluster:children]
master
node

Edit inventory/my-cluster/group_vars/all.yml

In my case edit the ansible_user to ubuntu

---
k3s_version: v1.17.5+k3s1
ansible_user: ubuntu
systemd_dir: /etc/systemd/system
master_ip: "{{ hostvars[groups['master'][0]]['ansible_host'] | default(groups['master'][0]) }}"
extra_server_args: ""
extra_agent_args: ""

Be ready for the power!

Execute the ansible-playbook to install k8s in the nodes.

ansible-playbook site.yml -i inventory/my-cluster/hosts.ini

Install kubectl in your computer

In my case macOS

brew install kubectl

Get the kubectl config from any of your master nodes

scp ubuntu@192.168.1.100:~/.kube/config ~/.kube/config

Verify installation.

Check that all nodes are in STATUS 'Ready'

kubectl get nodes

Deploy test

Create a local DNS entry for the test

sudo echo "192.168.1.100 test.com" >> /etc/hosts

I'm going to use traefik because is installed by default with k3s.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    name: nginx-service
spec:
  ports:
    - port: 80
      name: http
  selector:
    name: nginx-deployment
--------

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: "test.com"
    http:
      paths:
      - path: /
        backend:
          serviceName: nginx-service
          servicePort: 80

 Verify pods are up

kubectl get pods

Go to http://test.com on your browser

curl http://test.com

Its working!

Cleanup

Remember to remove the test.com line in /etc/hosts


This content originally appeared on DEV Community and was authored by NULLX


Print Share Comment Cite Upload Translate Updates
APA

NULLX | Sciencx (2021-05-06T11:47:20+00:00) Raspberry pi 4B kubernetes cluster. Retrieved from https://www.scien.cx/2021/05/06/raspberry-pi-4b-kubernetes-cluster/

MLA
" » Raspberry pi 4B kubernetes cluster." NULLX | Sciencx - Thursday May 6, 2021, https://www.scien.cx/2021/05/06/raspberry-pi-4b-kubernetes-cluster/
HARVARD
NULLX | Sciencx Thursday May 6, 2021 » Raspberry pi 4B kubernetes cluster., viewed ,<https://www.scien.cx/2021/05/06/raspberry-pi-4b-kubernetes-cluster/>
VANCOUVER
NULLX | Sciencx - » Raspberry pi 4B kubernetes cluster. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/06/raspberry-pi-4b-kubernetes-cluster/
CHICAGO
" » Raspberry pi 4B kubernetes cluster." NULLX | Sciencx - Accessed . https://www.scien.cx/2021/05/06/raspberry-pi-4b-kubernetes-cluster/
IEEE
" » Raspberry pi 4B kubernetes cluster." NULLX | Sciencx [Online]. Available: https://www.scien.cx/2021/05/06/raspberry-pi-4b-kubernetes-cluster/. [Accessed: ]
rf:citation
» Raspberry pi 4B kubernetes cluster | NULLX | Sciencx | https://www.scien.cx/2021/05/06/raspberry-pi-4b-kubernetes-cluster/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.