## K3S + MetalLB Install k3s + MetalLB in a cluster with RaspberryPi. #### Instructions: 1. Edit `/boot/cmdline.txt` file and the configuration at the end of line: `cgroup_memory=1 cgroup_enable=memory` 1. 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 ``` 1. Run the followed command in worker nodes: ```curl -sfL https://get.k3s.io | K3S_URL=https://:6443 K3S_TOKEN= sh -``` 1. When the installation is completed, let's relabel the worker nodes: ```kubectl label nodes kubernetes.io/role=worker``` 1. 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``` 1. The followed commands need to be executed in Control Node. 1. 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: - - ``` ```kubectl apply -f config.yml``` 1. To testing these configurations, let's deploy the a Nginx in the cluster: ```touch deployment.yml``` ```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``` ```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``` 1. To check if the the deployment and services are running as expected, run the followed commands: ```kubectl get pods``` ```kubectl get services``` 1. The output will be similar to this one: ```bash 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 443/TCP 19h nginx LoadBalancer 10.43.134.193 10.0.0.10 80:30341/TCP 19h ``` 1. The nginx service will be avaliable on External IP 10.0.0.10, to access in your browser. 1. If you need to remove the k3s installation just run the followed commands: 1. Control Plane: ```/usr/local/bin/k3s-uninstall.sh``` 2. Workers: ```/usr/local/bin/k3s-agent-uninstall.sh``` Useful links related to MetalLB configurations: [Reload IP configuration](https://github.com/metallb/metallb/issues/348) [IP Range change workflow](https://github.com/metallb/metallb/issues/308)