K3s Kubernetes Cluster with MetalLB Load Balancer: Cell Phones Lose Connection
K3s is a lightweight Kubernetes distribution designed for IoT and edge computing. It is highly efficient, certified Kubernetes, and fully compliant. This article will explore how to set up a K3s-based Kubernetes cluster with MetalLB load balancer and discuss an issue where cell phones lose connection when accessing IPs in the MetalLB IP range.
Prerequisites
- A server with at least 2 CPUs and 4GB of RAM
- K3s installed
- MetalLB installed
Setting up a K3s Kubernetes Cluster with MetalLB Load Balancer
To set up a K3s Kubernetes cluster with MetalLB load balancer, follow these steps:
- Install K3s on the server using the following command:
curl -sfL https://get.k3s.io | sh -- Install MetalLB by applying the following YAML configuration:
apiVersion: v1
kind: Namespace
metadata:
name: metalLB
---
apiVersion: metalLB.io/v1beta1
kind: MetalLB
metadata:
name: metalLB
spec:
configInline:
address-pools:
- name: default
protocol: layer2
avoid-buggy-ips: true
addresses:
- 192.168.1.240/28- Create a service with a type of LoadBalancer:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: my-appCell Phones Lose Connection when Accessing IPs in the MetalLB IP Range
When accessing IPs in the MetalLB IP range, cell phones may lose connection. This issue is caused by the way mobile networks handle IP addresses. Mobile networks use Carrier Grade NAT (CGNAT) to conserve IPv4 addresses. When a cell phone connects to a server using an IP address in the MetalLB IP range, the mobile network may not be able to route the traffic correctly, resulting in a lost connection.
Solution
To solve this issue, you can use a DNS name instead of an IP address. By using a DNS name, the mobile network will be able to route the traffic correctly, and the cell phone will not lose connection. To set up a DNS name for your service, follow these steps:
- Create a DNS record with a provider that supports dynamic DNS.
- Create a Kubernetes secret with the DNS record:
apiVersion: v1
kind: Secret
metadata:
name: my-service-dns
type: Opaque
data:
dns: - Update the service to use the DNS record:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: my-app
externalDNSName: - K3s is a lightweight Kubernetes distribution designed for IoT and edge computing.
- MetalLB is a load balancer for Kubernetes that works with K3s.
- Cell phones may lose connection when accessing IPs in the MetalLB IP range due to Carrier Grade NAT (CGNAT).
- To solve this issue, you can use a DNS name instead of an IP address.
References
- K3s: https://rancher.com/k3s
- MetalLB: