Install k3s + MetalLB in a cluster with RaspberryPi.
-
Edit
/boot/cmdline.txt
file and the configuration at the end of line:cgroup_memory=1 cgroup_enable=memory
-
On control node, generate a secret and install k3s:
TOKEN=`python3 -c "import secrets; print(secrets.token_hex(32))"`
curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644 --disable servicelb --token $TOKEN --bind-address <control_node_ip>
-
Run the followed command in worker nodes:
curl -sfL https://get.k3s.io | K3S_URL=https://<control_node_ip>:6443 K3S_TOKEN=<token> sh -
-
When the installation is completed, let's relabel the worker nodes:
kubectl label nodes <node_name> kubernetes.io/role=worker
-
Now, connect throught ssh with control node and install MetalLB:
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml
-
The followed commands need to be executed in Control Node.
-
Define the IP addresses that will be used by MetalLB, we need to create a config.yml file and apply with kubectl:
touch config.yml
apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: name: config namespace: metallb-system spec: addresses: - <first_node_ip_in_cluster>-<last_node_ip_in_cluster>
kubectl apply -f config.yml
-
To testing these configurations, let's deploy the a Nginx in the cluster:
touch deployment.yml
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: selector: matchLabels: app: nginx replicas: 3 template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:alpine ports: - containerPort: 80
touch service.yml
apiVersion: v1 kind: Service metadata: name: nginx spec: selector: app: nginx ports: - port: 80 targetPort: 80 type: LoadBalancer
kubectl apply -f deployment.yml
kubectl apply -f service.yml
-
To check if the the deployment and services are running as expected, run the followed commands:
kubectl get pods
kubectl get services
-
The output will be similar to this one:
pi@raspberrypi:~/k8s-nginx $ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-965685897-bddf7 1/1 Running 0 19h nginx-965685897-cfx4z 1/1 Running 0 19h nginx-965685897-n274m 1/1 Running 0 19h nginx-965685897-wxblb 1/1 Running 0 19h nginx-965685897-t2zhr 1/1 Running 0 19h pi@raspberrypi:~/k8s-nginx $ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 19h nginx LoadBalancer 10.43.134.193 10.0.0.10 80:30341/TCP 19h
-
The nginx service will be avaliable on External IP 10.0.0.10, to access in your browser.
-
If you need to remove the k3s installation just run the followed commands:
-
Control Plane:
/usr/local/bin/k3s-uninstall.sh
-
Workers:
/usr/local/bin/k3s-agent-uninstall.sh
-
Useful links related to MetalLB configurations: