Setting Up a Kubernetes Cluster on Raspberry Pi with K3s and MetalLB: A Practical Guide

Listen to this Post

In this article, we explore how to set up a Kubernetes cluster on a Raspberry Pi using K3s and MetalLB. This setup allows you to run Kubernetes outside of the public cloud, providing a cost-effective and efficient way to manage containerized applications.

Step-by-Step Guide

1. Install K3s on Raspberry Pi:

K3s is a lightweight Kubernetes distribution ideal for resource-constrained environments like the Raspberry Pi. To install K3s, run the following command:

curl -sfL https://get.k3s.io | sh -

2. Verify K3s Installation:

After installation, verify that K3s is running correctly:

sudo kubectl get nodes

3. Install MetalLB:

MetalLB is a load balancer for Kubernetes that works in bare-metal environments. To install MetalLB, apply the following manifest:

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml

4. Configure MetalLB:

Create a configuration file for MetalLB to define the IP address range it will use:

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default-pool
namespace: metallb-system
spec:
addresses:
- 192.168.1.240-192.168.1.250

Apply the configuration:

kubectl apply -f metallb-config.yaml

5. Deploy a Sample Application:

Deploy a sample application to test the setup:

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=LoadBalancer

6. Access the Application:

Retrieve the external IP assigned by MetalLB and access the application:

kubectl get svc nginx

What Undercode Say

Setting up a Kubernetes cluster on a Raspberry Pi using K3s and MetalLB is a powerful way to learn and experiment with Kubernetes in a cost-effective manner. This setup is particularly useful for developers and IT professionals who want to understand how Kubernetes operates outside of cloud environments. The combination of K3s and MetalLB provides a lightweight yet robust solution for managing containerized applications.

To further enhance your Kubernetes skills, consider exploring the following commands and tools:

  • Helm: A package manager for Kubernetes that simplifies application deployment.
    helm install my-app ./my-app-chart
    

  • kubectl port-forward: Forward a local port to a port on a pod.

    kubectl port-forward pod/my-pod 8080:80
    

  • kubectl logs: View logs from a specific pod.

    kubectl logs my-pod
    

  • kubectl exec: Execute a command in a container.

    kubectl exec -it my-pod -- /bin/sh
    

  • kubectl describe: Get detailed information about a resource.

    kubectl describe pod my-pod
    

For more advanced configurations, consider exploring the official Kubernetes documentation and community resources. Additionally, integrating monitoring tools like Prometheus and Grafana can provide valuable insights into your cluster’s performance.

Useful Links:

By mastering these tools and commands, you can build a solid foundation in Kubernetes and enhance your ability to manage containerized applications effectively.

References:

Hackers Feeds, Undercode AIFeatured Image