Skip to main content

Networking

Networking is a very important part of any cluster.
For our purposes, we will be configuring K3s with a load balancer thats distributed across the nodes, instead of relying on an external load balancer, which isn't as common in a home setting.

Key concept

Deployment -> Service -> Ingress Rule.

Deployment

A deployment, pod or container is what you application is.

Service

Your service is what points at that object (we'll go over the config for this later), and allows you to spin up/down the deployment without reconfiguring. Think of it like another load balancer, just for your application.
This will be 'pointed' at your deployment selectors.

Ingress

This is what tells your ingress-controller, in this case Traefik, what to point DNS names at.
This will be 'pointed' at your service.

Step 1 - Install MetalLB

We need to install MetalLB, which will be our Kubernetes hosted load balancer.
Run the following commands from your admin workstation -

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

Configure MetalLB Secrets (Optional)

We can also configure MetalLB to secure its communications behind a secret.
You can run the following command to set this -

kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"

Configure MetalLb IP Range

Next we need to tell MetalLB what IPs from your local LAN it can use and allocated.

Create a new file called metallb_config.yaml, and copy the below into it.

---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default
namespace: metallb-system
spec:
addresses:
- 192.168.0.230/32

At the bottom, adjust your address range, or ranges if you want, that MetalLB can use. Next, apply it to MetalLB -

kubectl apply -f metallb_config.yaml
tip

We can add additional address-pools to this configuration for MetalLB, giving us the ability to 'point' different load balancers at different pools, dependant on what we want them to do/their use. Just add in another - name block, and give it a unique name.
You can also specify individual IPs by using its CIDR notation.

Next Step

Next, go to the next step, Storage.
Or,
Go back to the index page.