application-research / estuary-hosted-infrastructure

The main repository for EHI
MIT License
3 stars 0 forks source link

Add MetalLB to expose Kubernetes resources as LoadBalancers #21

Closed Zorlin closed 1 year ago

Zorlin commented 1 year ago

We need to install and setup MetalLB to allow us to expose Kubernetes resources such as PostgreSQL to public routing.

Steps

### Tasks
- [x] Define IP range
- [x] Install MetalLB
- [x] Create object for that IP range
- [x] Test
Zorlin commented 1 year ago

IP range will be 10.24.5.1 through 10.24.5.254

apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: prod-pool-a
  namespace: metallb-system
spec:
  addresses:
  - 10.24.5.0/24

Installation: helm install metallb metallb/metallb -n metallb-system

Apply the pool:

$ kubectl apply -f pool.yaml 
ipaddresspool.metallb.io/prod-pool-a created

Apply the L2 config:

$ cat l2.yaml 
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: prod-pool-a-layer2
  namespace: metallb-system
spec:
  ipAddressPools:
  - prod-pool-a
$ kubectl apply -f l2.yaml 
l2advertisement.metallb.io/prod-pool-a-layer2 created
Zorlin commented 1 year ago

Testing:

$ cat test.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
    - name: nginx-container
      image: nginx
      ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: LoadBalancer
  selector:
    app: nginx-pod
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
$ kubectl apply -f test.yaml 
pod/nginx-pod created
service/nginx-service created