πŸš€ Deploying Scalable WordPress on Raspberry Pi Cluster with K3s and Kubernetes πŸ–₯️

Welcome to the exciting world of Kubernetes! 🌐 In this guide, we’ll show you how to build a scalable infrastructure using K3s on Raspberry Pi, perfect for hosting a WordPress site. We’ll cover everything from setup to scaling and monitoring, all using lightweight Raspberry Pis.

🎯 Objectives Our mission is simple: create a powerful, scalable infrastructure that effortlessly handles WordPress deployment. Ready to roll up your sleeves? Let’s dive in!


πŸ› οΈ What You’ll Need

Hardware:

  • 5 Raspberry Pis (or just 1 if you’re starting small)
  • Router & Switch
  • SD Cards & Ethernet Cables
  • Power Supply for each Pi
  • External Drive for backups

Software:

  • Win32 Disk Imager for disk setup
  • K3s for ARM architecture
  • Raspberry Pi OS Lite 64-bit

Knowledge:

  • Basics of Linux, Kubernetes, and Networking 🧠

πŸ“¦ Step 1: Setting Up Raspberry Pis

  1. Prepare Your Hardware:
    • Power up your Raspberry Pis and connect them to the network.
  2. Install the OS:
    • Use Raspberry Pi Imager to flash Raspberry Pi OS Lite (64-bit) onto SD cards.
    • Insert the SD card, power on the Pi, and complete the initial setup.
  3. Network Configuration:
    • Edit network settings on each Pi to assign static IPs. This ensures stable communication between nodes.
    • Example:
      sudo nano /etc/network/interfaces
      auto eth0 iface eth0
      inet static
      address 192.168.1.2
      netmask 255.255.255.0
      gateway 192.168.1.1
    • Save and restart the network service.
  4. Enable SSH Access:
    • SSH allows remote access to each Pi. Activate it with:
      sudo raspi-config

πŸ—οΈ Step 2: Master Node Configuration

  1. Install K3s on Master Node:
    • Log into the master Pi and install K3s with:
      curl -sfL https://get.k3s.io | sh -
  2. Configure Master Node Components:
    • Export the kubeconfig file:
      export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
    • Install Helm (Kubernetes package manager):
      sudo snap install helm --classic helm init

🌍 Step 3: Setting Up Worker Nodes

  1. Install K3s on Worker Nodes:
    • SSH into each worker Pi and install K3s, joining them to the cluster:
      curl -sfL https://get.k3s.io | K3S_URL=https://<master-ip>:6443 K3S_TOKEN=<node-token> sh -
  2. Verify Node Status:
    • On the master node, check if all nodes are ready:
      sudo k3s kubectl get nodes

🌐 Step 4: Network Configuration

  1. Set Static IPs:
    • Consistent IPs are key for smooth operation. Set these in the /etc/network/interfaces file.
  2. Troubleshoot Connectivity:
    • If issues arise, use ping tests between nodes and ensure SSH works.
    • Command:
      ping <other-node-ip>

πŸ—„οΈ Step 5: Persistent Volume Setup

  1. Create Persistent Volumes (PVs):
    • Define storage needs in a YAML file:
      apiVersion: v1 kind:
      PersistentVolume metadata:
      name: pv-local
      spec: capacity:
      storage: 1Gi
      accessModes: - ReadWriteOnce
      hostPath: path: "/mnt/data"
    • Apply with:
      sudo k3s kubectl apply -f pv.yaml
  2. Test PVs:
    • Deploy a test pod to ensure data persistence.

🌟 Step 6: Deploy WordPress on Kubernetes

  1. Create Deployment YAML:
    • Example WordPress YAML:

  2. apiVersion: apps/v1 kind:
    Deployment metadata:
    name: wordpress
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: wordpress
    template: metadata:
    labels:
    app: wordpress
    spec:
    containers:
    - name: wordpress
    image: wordpress:latest
    env:
    - name: WORDPRESS_DB_HOST
    value: mysql-service
    - name: WORDPRESS_DB_PASSWORD
    valueFrom: secretKeyRef:
    name: mysql-secret
    key: password
    ---
    apiVersion: v1
    kind: Service metadata:
    name: wordpress-service
    spec:
    selector:
    app: wordpress ports:
    - protocol:
    TCP port: 80
    targetPort: 80
    type: LoadBalancer
  3. Access WordPress:
    • Open your browser and navigate to the external IP assigned to the WordPress service.

πŸ“ˆ Step 7: Scaling WordPress Deployment

  1. Enable Autoscaling:
    • Configure autoscaling with a Horizontal Pod Autoscaler (HPA):
      apiVersion: autoscaling/v2beta2 kind: HorizontalPodAutoscaler metadata: name: wordpress-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: wordpress minReplicas: 1 maxReplicas: 5 metrics: - type: Resource resource: name: cpu targetAverageUtilization: 80
  2. Test Scalability:
    • Use load testing tools to simulate traffic and monitor scaling:
      ab -n 10000 -c 10 http://<wordpress-service-ip>/

πŸ“Š Step 8: Monitoring with Prometheus and Grafana

  1. Deploy Prometheus:
    • Collect metrics to monitor your cluster’s performance.
  2. Set Up Grafana:
    • Visualize metrics using Grafana dashboards. Import Kubernetes dashboards for detailed insights.

πŸŽ‰ Conclusion

You’ve successfully deployed a scalable WordPress site using Kubernetes on Raspberry Pi! This guide is just the beginning. Keep exploring and tweaking your setup to match your needs. 🌍

Happy clustering! πŸŽ‰


πŸ”— Useful Resources:

We will be happy to hear your thoughts

Leave a reply

Experience the Power of Preinstalled OS Drives and Booting Guides
Logo
Compare items
  • Total (0)
Compare
0
Ninja Silhouette 9 hours ago

Joe Doe in London, England purchased a

Joe Doe in London?

Joe Doe in London, England purchased a

Joe Doe in London?

Joe Doe in London, England purchased a

Joe Doe in London?

Joe Doe in London, England purchased a