First of all vlan tools should be installed on Ubuntu:

apt-get install vlan

Vlan configuration

add section to /etc/network/interfaces.d/50-cloud-init.cfg

auto vlan10

iface vlan10 inet static

address 192.168.10.1

netmask 255.255.255.0

vlan_raw_device eth0

add section to /etc/netplan/01-netcfg.yaml (for people who use netplan)

vlans:

vlan10:

id: 0

link: ens4

addresses: [192.168.10.0/24]

Don’t forget restart network subsystem after changes.

Install MetalLB

Installation is pretty easy:

# kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml

Check if speaker and controller is UP without any errors

# kubectl get pods -n metallb-system

Define IP range for LB

Allocate chunk of IP space for MetalLB services. We will use 192.168.10.240–192.168.10.250 for this.

Prepare ConfigMap yaml file and deploy it to kubermetes cluster. Example of ConfigMap located in MetalLB GitHub repository.

Example of ConfigMap yaml file:

apiVersion: v1

kind: ConfigMap

metadata:

namespace: metallb-system

name: config

data:

config: |

address-pools:

- name: default

protocol: layer2

addresses:

- 192.168.10.240-192.168.10.250

Layer2 mode is using here, but MetalLB can also be configured with BGP mode. See the BGP MetalLB tutorial.

Configuring pod and LB service for testing

Now we can configure MetalLB service for nginx pod (just for test)

apiVersion: v1

kind: Service

metadata:

name: nginx

spec:

ports:

- name: http

port: 80

protocol: TCP

targetPort: 80

selector:

app: nginx

type: LoadBalancer

and install nginx pod

apiVersion: apps/v1beta2

kind: Deployment

metadata:

name: nginx

spec:

selector:

matchLabels:

app: nginx

template:

metadata:

labels:

app: nginx

spec:

containers:

- name: nginx

image: nginx:1

ports:

- name: http

containerPort: 80

Or just execute tutorial yaml file: # kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/tutorial-2.yaml

Results

In the result we can see External IP assigned to our LoadBalancer

# kubectl get services

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h

nginx LoadBalancer 10.107.44.239 192.168.10.240 80:32025/TCP 22h

Let’s ping our pod

# ping 192.168.10.240

PING 192.168.10.240 (192.168.10.240) 56(84) bytes of data.

From 192.168.10.1 icmp_seq=1 Destination Host Unreachable

From 192.168.10.1 icmp_seq=2 Destination Host Unreachable

From 192.168.10.1 icmp_seq=3 Destination Host Unreachable

Oops…. host is not reachable …. Yes, because we open port 80 for communication with nginx pod. But, if we execute curl:

curl http://192.168.10.240

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

body {

width: 35em;

margin: 0 auto;

font-family: Tahoma, Verdana, Arial, sans-serif;

}

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p> Welcome to nginx! body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif; Welcome to nginx! If you see this page, the nginx web server is successfully installed andworking. Further configuration is required.

<a href="

Commercial support is available at

<a href=" For online documentation and support please refer tohttp://nginx.org/ ">nginx.org.

Commercial support is available athttp://nginx.com/ ">nginx.com. <p><em>Thank you for using nginx.</em></p>

</body>

</html>

we will see the nginx output :) and this is awesome.

Useful links